Azure Blob using service principal

Hello, I need to configure rclone for azureblob using oauth2 to get an access token owning client_id and client_key:

POST https://login.microsoftonline.com/{{tenant_id}}/oauth2/token

body:
client_id: xxxxx (id_service principal)
client_secret: XXXXXXXXXXXXXXXXXXXXXXX
resource: https://storage.azure.com/
grant_type: client_credentials

thnx a lot.

oauth isn't one of the supported auth methods for the azureblob backend at the moment.

This looks like the right docs I think

Not sure how to use that with the go SDK though: https://godoc.org/github.com/Azure/azure-storage-blob-go/azblob

Is this something you'd like to help with?

using a shell script:

#!/bin/bash

client_id="xxx"
client_secret="yyy"
app_id="zzz"
storage_account="myaccount"
container_name="backup"

# url encoded resource
resource="https%3A%2F%2Fstorage.azure.com%2F"

curl_opts='-H "Content-Type: application/x-www-form-urlencoded"'
mthd="https"

# Access Token
json=$(curl -s -X POST -d "grant_type=client_credentials&resource=${resource}&client_id=${client_id}&client_secret=${client_secret}" "${mthd}://login.microsoftonline.com/${app_id}/oauth2/token?api-version=1.0")

if [[ $? -gt 0 || ${#json} -lt 80 ]]; then
echo "error getting token"
exit
fi

access_token=$(awk '/access_token/ {if (match($0,/"access_token":"([^"]+)/,at)) print at[1];}' <<< $json)
token_type=$(awk '/token_type/ {if (match($0,/"token_type":"([^"]+)/,tt)) print tt[1];}' <<< $json)

body=$(curl -s \
-H "Authorization: $token_type $access_token" \
-H 'x-ms-blob-type: BlockBlob' \
-H 'x-ms-version: 2018-03-28' \
"${mthd}://${storage_account}.blob.core.windows.net/${container_name}?restype=container&comp=list")

That looks useful :slight_smile: Can you please make a new issue on github then we can work on it there - thanks.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.