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 (my notes):
- NewAuthorizerFromFile method
- NewAuthorizerFromEnvironment method (this post)
This function definition looks like below :
Looks pretty simple, to begin with. The definition tells us that another function called getAuthenticationSettings() is fetching some authentication settings and returns a struct of type settings then at the end return settings.getAuthorizer() is called.
I use VSCode (with Go extensions) and I can go to each method and press F12 key to go to the function definition for it. It reveals the below definition in the same auth.go file for the first function called.
Now the above function is straight forward as it tries to read the environment variable using os.Getenv() method and construct the structure and returns it.
Once we have the struct returned, there is a method attached to it which looks like below:
This one is interesting as it tells the order in which the environment variables are given preference e.g.
- Client Credentials - Specify the env vars:
- AZURE_CLIENT_ID
- AZURE_CLIENT_SECRET
- AZURE_TENANT_ID
- Client Certificate - Specify the env vars:
- AZURE_CERTIFICATE_PATH
- AZURE_CERTIFICATE_PASSWORD
- AZURE_TENANT_ID
- Username Password - Specify the env vars:
- AZURE_USERNAME
- AZURE_PASSWORD
- AZURE_CLIENT_ID
- AZURE_TENANT_ID
- MSI - specify the env vars:
- AZURE_AD_RESOURCE
- AZURE_CLIENT_ID
So, in order to use this method, you can choose any of the above ways of authenticating but you have to populate these env vars beforehand.
Also, auth.go file has a bunch of more functions that can be used for authenticating as well.