Skip to content

Commit

Permalink
Updated README about the Managed identity client usage
Browse files Browse the repository at this point in the history
  • Loading branch information
4gust committed Nov 26, 2024
1 parent 949376f commit a9e876f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ Acquiring tokens with MSAL Go follows this general pattern. There might be some
}
confidentialClient, err := confidential.New("https://login.microsoftonline.com/your_tenant", "client_id", cred)
```
* Initializing a Managed Identity client for SystemAssigned:

```go
import mi "github.com/AzureAD/microsoft-authentication-library-for-go/apps/managedidentity"
// Managed identity client have a type of ID required, SystemAssigned or UserAssigned
miSystemAssigned, err := mi.New(mi.SystemAssigned())
if err != nil {
// TODO: handle error
}
```
* Initializing a Managed Identity client for UserAssigned:

```go
import mi "github.com/AzureAD/microsoft-authentication-library-for-go/apps/managedidentity"
// Managed identity client have a type of ID required, SystemAssigned or UserAssigned
miSystemAssigned, err := mi.New(mi.UserAssignedClientID("YOUR_CLIENT_ID"))
if err != nil {
// TODO: handle error
}
```

1. Call `AcquireTokenSilent()` to look for a cached token. If `AcquireTokenSilent()` returns an error, call another `AcquireToken...` method to authenticate.

Expand Down Expand Up @@ -96,6 +118,16 @@ Acquiring tokens with MSAL Go follows this general pattern. There might be some
accessToken := result.AccessToken
```

* ManagedIdentity clietn can simply call `AcquireToken()`:
```go
resource := "<Your resource>"
result, err := miSystemAssigned.AcquireToken(context.TODO(), resource)
if err != nil {
// TODO: handle error
}
accessToken := result.AccessToken
```

## Community Help and Support

We use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browse existing issues to see if someone has had your question before. Please use the "msal" tag when asking your questions.
Expand Down

0 comments on commit a9e876f

Please sign in to comment.