My personal notes on how to authenticate to Azure in the GoLang code.
The auth package lives at "github.com/Azure/go-autorest/autorest/azure/auth"
In the above package, at the moment I have explored below two functions:
The struct where the JSON file is unmarshaled looks like below, make a note that all these fields are read from the JSON file:
The second method will be covered in the Part 2 of the post.
The auth package lives at "github.com/Azure/go-autorest/autorest/azure/auth"
In the above package, at the moment I have explored below two functions:
- NewAuthorizerFromFile method
- NewAuthorizerFromEnvironment method
NewAuthorizerFromFile
I prefer using this method when doing local development but it is not suited for Production since the file containing auth metadata lives in the file system.
The function definition looks like:
So, this method takes a baseURI of the ARM Endpoint and then it looks for an environment variable AZURE_AUTH_LOCATION.
The value of this env var is pointing to a file containing required metadata for authenticating to Azure e.g. SubscriptionId, ClientID etc.
The struct where the JSON file is unmarshaled looks like below, make a note that all these fields are read from the JSON file:
Note - The above metadata file can be created using Az CLI and stored on the filesystem, using below:
az ad sp create-for-rbac —sdk-auth > azureauth.json
The second method will be covered in the Part 2 of the post.