Use Azure Go SDK to enumerate app credentials

139 Views Asked by At

I'm new to Azure and struggling to generate the Go code that's equivalent to az ad app credential list --id=${ID}.

I find the Azure Go SDK to be comprehensive but the documentation is lacking. Is there a general-purpose mechanism by which I can determine the Go SDK from an az command?

Update So, it appears the services package (containing services/graphrbac) is deprecated and that azidentity is the preferred auth package. And I can continue to use azidentity.NewDefaultAzureCredential

But, I'm still unable to determine the Go package that matches az ad app credential list.

I asked ChatGPT and it gave me something (non-working) that uses the Graph RBAC API with which I'm entirely unfamiliar

I have known-working code that uses azidentity.NewDefaultAzureCredential(nil) to authenticate using both the CLI's credentials and a certificate and, would like to stick with this familiar (powerful) mechanism if possible.

It's unclear to me whether secretClient.ListKeyCredentials is even the correct package/method that I need to use.

Any guidance would be appreciated.

Which of the two tags is correct? azure-sdk-for-go or azure-sdk-go?

1

There are 1 best solutions below

3
On

You can try calling the ListPasswordCredentials function from the graphrbac go package to fetch the passwordCredentials associated with an application. Please update the below sample code:

    client:= graphrbac.NewApplicationsClient(tenantID)
    client.Authorizer = graphAuth

    // Call the ListPasswordCredentials method to get a list of password credentials for the specified application object ID

    list, err := client.ListPasswordCredentials(appObjID)
    if err != nil {
        panic(err)
    }

    // Iterate over the list of password credentials and print the properties of each credential
    

Hope this helps.