Skip to content

Commit 26299b2

Browse files
authored
Merge branch 'main' into feature/set-interactive-auth-success-and-error-pages
2 parents f419d6a + fc56b03 commit 26299b2

37 files changed

+3377
-201
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: go build ./apps/...
4040

4141
- name: Unit Tests
42-
run: go test -race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/...
42+
run: go test -race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/... ./apps/managedidentity/...
4343
# Intergration tests runs on ADO
4444
# - name: Integration Tests
4545
# run: go test -race ./apps/tests/integration/...

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ Acquiring tokens with MSAL Go follows this general pattern. There might be some
5050
}
5151
confidentialClient, err := confidential.New("https://login.microsoftonline.com/your_tenant", "client_id", cred)
5252
```
53+
* Initializing a Managed Identity client for SystemAssigned:
54+
55+
```go
56+
import mi "github.com/AzureAD/microsoft-authentication-library-for-go/apps/managedidentity"
57+
58+
// Managed identity client have a type of ID required, SystemAssigned or UserAssigned
59+
miSystemAssigned, err := mi.New(mi.SystemAssigned())
60+
if err != nil {
61+
// TODO: handle error
62+
}
63+
```
64+
* Initializing a Managed Identity client for UserAssigned:
65+
66+
```go
67+
import mi "github.com/AzureAD/microsoft-authentication-library-for-go/apps/managedidentity"
68+
69+
// Managed identity client have a type of ID required, SystemAssigned or UserAssigned
70+
miSystemAssigned, err := mi.New(mi.UserAssignedClientID("YOUR_CLIENT_ID"))
71+
if err != nil {
72+
// TODO: handle error
73+
}
74+
```
5375

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

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

121+
* ManagedIdentity clietn can simply call `AcquireToken()`:
122+
```go
123+
resource := "<Your resource>"
124+
result, err := miSystemAssigned.AcquireToken(context.TODO(), resource)
125+
if err != nil {
126+
// TODO: handle error
127+
}
128+
accessToken := result.AccessToken
129+
```
130+
99131
## Community Help and Support
100132

101133
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.

apps/confidential/confidential.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ func WithInstanceDiscovery(enabled bool) Option {
305305
// If an invalid region name is provided, the non-regional endpoint MIGHT be used or the token request MIGHT fail.
306306
func WithAzureRegion(val string) Option {
307307
return func(o *clientOptions) {
308-
o.azureRegion = val
308+
if val != "" {
309+
o.azureRegion = val
310+
}
309311
}
310312
}
311313

@@ -637,7 +639,7 @@ func (cca Client) AcquireTokenByUsernamePassword(ctx context.Context, scopes []s
637639
if err != nil {
638640
return AuthResult{}, err
639641
}
640-
return cca.base.AuthResultFromToken(ctx, authParams, token, true)
642+
return cca.base.AuthResultFromToken(ctx, authParams, token)
641643
}
642644

643645
// acquireTokenByAuthCodeOptions contains the optional parameters used to acquire an access token using the authorization code flow.
@@ -731,7 +733,7 @@ func (cca Client) AcquireTokenByCredential(ctx context.Context, scopes []string,
731733
if err != nil {
732734
return AuthResult{}, err
733735
}
734-
return cca.base.AuthResultFromToken(ctx, authParams, token, true)
736+
return cca.base.AuthResultFromToken(ctx, authParams, token)
735737
}
736738

737739
// acquireTokenOnBehalfOfOptions contains optional configuration for AcquireTokenOnBehalfOf

0 commit comments

Comments
 (0)