Hello,
When using the GraphRBAC API I always receive the error:
graphrbac.ServicePrincipalsClient#List: Failure responding to request: StatusCode=401 -- Original Error: autorest/azure: Service returned an error. Status=401 Code="Unknown" Message="Unknown service error" Details=[{"odata.error":{"code":"Authentication_MissingOrMalformed","message":{"lang":"en","value":"Access Token missing or malformed."}}}]
Here is the code that creates this:
package main
import (
"context"
"fmt"
"os"
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/Azure/go-autorest/autorest/azure/auth"
)
func main() {
// Create Context handler
ctx := context.Background()
// Service Principal Client
spClient := graphrbac.NewServicePrincipalsClient(os.Getenv("AZURE_TENANT_ID"))
authorizer, err := auth.NewAuthorizerFromEnvironment()
if err == nil {
spClient.Authorizer = authorizer
} else {
panic(err)
}
client, err := spClient.List(ctx, "")
fmt.Printf("%v\n", client)
fmt.Printf("%v", err)
}
I am expecting to be able to query Azure AD via this SDK.
Hi @jhendrixMSFT would you please check on this? Seems something wrong with authorization or something wrong with the service.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure
The problem here is that the resource ID for the authorizer is incorrect; it should be the graph resource ID (the default is the resource manager ID).
authorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(azure.PublicCloud.ResourceIdentifiers.Graph)
Taken from the example code here.
Issue closed, after changing the authorizer I can successfully authenticate with the Graph API.
Thanks @jhendrixMSFT
Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.
Most helpful comment
The problem here is that the resource ID for the authorizer is incorrect; it should be the graph resource ID (the default is the resource manager ID).
Taken from the example code here.