Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Managed Identity Support #552

Merged
merged 208 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
995fa3c
Changes for running
AndyOHart Aug 21, 2024
0993a3f
* Adds .md file for managed identitys public api
AndyOHart Aug 21, 2024
1053165
Update docs/managedidentity_public_api.md
AndyOHart Aug 21, 2024
aadf13d
Makes DefaultToIMDS the default 0 value
AndyOHart Aug 22, 2024
2fe36df
Merge branch 'andyohart/managed-identity-basic-class-implementation' …
AndyOHart Aug 22, 2024
e82f85d
Merge pull request #499 from AzureAD/andyohart/managed-identity-basic…
AndyOHart Aug 22, 2024
1d2f3e8
Initial system assgined for acquire token
4gust Aug 27, 2024
63e6bed
Added a simple version of getting token.
4gust Aug 27, 2024
69a039c
added IMDB for SAMI
4gust Sep 2, 2024
7c94182
Reverted the test app to original state
4gust Sep 2, 2024
2646418
Formatting changes
4gust Sep 2, 2024
4db1c7e
Added methods for UAMI
4gust Sep 3, 2024
3bf0383
Updated and cleaned up MI for SAMI
4gust Sep 4, 2024
8c3fed1
Update apps/managedidentity/managedidentity.go
4gust Sep 4, 2024
5eb2919
Resolved some comments.
4gust Sep 10, 2024
29583da
Merge branch 'acquire-token-for-mise' of https://github.com/AzureAD/m…
4gust Sep 10, 2024
64e4705
Updated test
4gust Sep 10, 2024
a7e760a
Updated the Identity method for feedback
4gust Sep 11, 2024
df2ad5a
Passed context to http request
4gust Sep 11, 2024
287963e
Updated service errors handling and tests
4gust Sep 13, 2024
df9faf1
Updated tests to use mock
4gust Sep 16, 2024
5395b9a
small update
4gust Sep 16, 2024
6a72df2
Added a withStatusCode method in mock
4gust Sep 17, 2024
b293a60
Update apps/internal/mock/mock.go
4gust Sep 17, 2024
c2b9127
Updated the method usage for WithHTTPStatusCode
4gust Sep 17, 2024
e451611
Update apps/managedidentity/managedidentity_test.go
4gust Sep 20, 2024
9912ee9
Update apps/managedidentity/managedidentity_test.go
4gust Sep 20, 2024
7f147d4
Removed typed data from test
4gust Sep 20, 2024
a2b0a2a
Merge branch 'acquire-token-for-mise' of https://github.com/AzureAD/m…
4gust Sep 20, 2024
82b1155
Updated test to return json error
4gust Sep 20, 2024
522883a
Updating sample app
4gust Sep 20, 2024
6ad761f
Updated the MI identity for UAMI with "UserAssigned" as prefix
4gust Sep 23, 2024
1dcad54
Added Correct response format in test
4gust Sep 24, 2024
149c6aa
Removed Elements from the response that were not used
4gust Sep 24, 2024
e24ca26
Removed un used fields
4gust Sep 24, 2024
cac4441
Removed unused vairable.
4gust Sep 24, 2024
d967d31
Update apps/managedidentity/managedidentity.go
4gust Sep 24, 2024
3367c04
Updated to have more coverage
4gust Sep 24, 2024
08a9465
Merge branch 'acquire-token-for-mise' of https://github.com/AzureAD/m…
4gust Sep 24, 2024
795cd67
Updated tests to test request
4gust Sep 24, 2024
6b9cd68
Removed some tests which were redundant
4gust Sep 25, 2024
b6ec2ee
Merge pull request #500 from AzureAD/acquire-token-for-mise
4gust Sep 25, 2024
4fef77d
Adds documentation for running IMDS locally
AndyOHart Sep 25, 2024
882087b
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
AndyOHart Sep 26, 2024
c0ba80f
update testing doc
AndyOHart Sep 26, 2024
edbd6d6
fix failing lint
AndyOHart Sep 26, 2024
559e985
Merge pull request #512 from AzureAD/imds-documentation
AndyOHart Sep 26, 2024
a0dd42e
Merge branch 'main' of https://github.com/AzureAD/microsoft-authentic…
AndyOHart Sep 26, 2024
c5febcb
adds tracking for the integration tests that are disabled
AndyOHart Sep 26, 2024
e940016
Added in memory cache support for IMDS - SAMI and UAMI
4gust Oct 4, 2024
52933ff
Removing Resource
4gust Oct 7, 2024
ab3bb2b
Added static caching
4gust Oct 8, 2024
8a49fa0
Update apps/managedidentity/managedidentity.go
4gust Oct 11, 2024
f4915fa
resolved PR comments
4gust Oct 11, 2024
1801963
Removed http.client from cache
4gust Oct 14, 2024
a43d111
Removed cacheWrite
4gust Oct 14, 2024
fafb799
Updated some test error messages
4gust Oct 14, 2024
72bea12
Delete apps/tests/devapps/managedidentity/serialized_cache.json
4gust Oct 15, 2024
0311da2
Merge branch '4gust/imds-cache' of https://github.com/AzureAD/microso…
4gust Oct 15, 2024
918ded0
Update apps/managedidentity/managedidentity.go
4gust Oct 15, 2024
9a81784
Resolved some PR comments
4gust Oct 15, 2024
31b4118
updating sample
4gust Oct 15, 2024
e52a603
updating the expires_in usage
4gust Oct 15, 2024
b3921d9
updated variable
4gust Oct 15, 2024
ae4718d
Update managedidentity_sample.go
4gust Oct 15, 2024
94888b1
Added a cachemanager nil check
4gust Oct 16, 2024
fd132a5
Fixing a possible panic in sotrage
4gust Oct 16, 2024
b0c2403
Update apps/managedidentity/managedidentity_test.go
4gust Oct 21, 2024
84b62c6
Comments resolved.
4gust Oct 21, 2024
7c51221
Merge pull request #514 from AzureAD/4gust/imds-cache
4gust Oct 21, 2024
f8480ad
Implemented Retry Policy
4gust Oct 21, 2024
10df4c9
Fixed the tests
4gust Oct 22, 2024
1782b07
Updated the retry policy to respect context
4gust Oct 23, 2024
a60fd6d
Updated the variable name to remove negation
4gust Oct 24, 2024
716cbce
Update managedidentity.go
4gust Oct 29, 2024
8319e22
Update managedidentity_test.go
4gust Oct 29, 2024
31fc7a0
Update managedidentity.go
4gust Nov 1, 2024
54ff161
Update managedidentity.go
4gust Nov 6, 2024
4e2ed03
Added a context exit for request.
4gust Nov 7, 2024
0a8c604
Consider scopes when searching cache
chlowell Nov 7, 2024
fb8f1c4
normalize resource in AcquireToken
chlowell Nov 7, 2024
b5bff8e
testing the ado build on the personal branch
4gust Sep 25, 2024
b7f69c1
updated the build path
4gust Sep 25, 2024
3f86c34
updating path
4gust Sep 25, 2024
c4e46cf
updating the cert creation script
4gust Sep 25, 2024
3bf9f81
update path
4gust Sep 25, 2024
c10e633
comment some tests
4gust Sep 25, 2024
f15746b
uploading working tests
4gust Sep 25, 2024
e897a26
Added README for running integration tests
4gust Sep 26, 2024
b060c7f
Skipping 2 tests
4gust Sep 26, 2024
f04d4b4
Wrap ResolveEndpoints error
kgeckhart Oct 4, 2024
ee88303
Update build_test.yaml for Azure Pipelines
bgavrilMS Oct 7, 2024
68cc4fe
Added Region auto enable
4gust Oct 30, 2024
9d5e86c
Separated test
4gust Oct 31, 2024
d88efcf
Updated variableName
4gust Oct 31, 2024
9158019
Update go.yml to remove Integration tests
4gust Oct 31, 2024
2adf0dd
refactor: remove UserRealmURIPrefix from authority.Info
handsomejack-42 Apr 3, 2024
78f4fba
refactor(oauth): use named tests for WithTenant to improve test outpu…
handsomejack-42 Apr 9, 2024
0975c01
test(oauth): add WithTenant test-cases to increase method test coverage
handsomejack-42 Apr 9, 2024
c566990
refactor(oauth): use constructor for new client in comm.HTTPClient.JS…
handsomejack-42 Apr 15, 2024
80cb6c4
refactor(oauth): rename aad instance discovery endpoint const
handsomejack-42 Apr 15, 2024
e39ce1c
refactor(oauth): make WithTenant extensible with authority types
handsomejack-42 Apr 15, 2024
c717825
refactor(authority): use authority.ADFS instead of re-defined ADFS const
handsomejack-42 May 29, 2024
a4fe72c
refactor(confidential): fakeClient accepts authority as param
handsomejack-42 Apr 15, 2024
17acbeb
feat(oauth): add support for dSTS authority type
handsomejack-42 Apr 15, 2024
995c080
Fix invalid authority uri
bgavrilMS Nov 6, 2024
46b3a48
If authority segments <3, throw
bgavrilMS Nov 6, 2024
b54495a
Fix WithTenantID("adfs") regression (#529)
chlowell Nov 6, 2024
9b700f7
Create release.md
bgavrilMS Nov 7, 2024
7fb6eb1
Merge branch 'main' into andyohart/managed-identity
4gust Nov 8, 2024
00c0325
tidying
chlowell Nov 8, 2024
ef878df
added support for Azure arc
4gust Nov 11, 2024
5d3033c
Update managedidentity.go
4gust Nov 12, 2024
7146f26
Resolved comments for GetSource
4gust Nov 12, 2024
46efcf8
Merge pull request #531 from AzureAD/chlowell/cache
4gust Nov 13, 2024
63b7e52
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
4gust Nov 13, 2024
f4bbc08
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
4gust Nov 13, 2024
53693e7
Update managedidentity_test.go
4gust Nov 14, 2024
b7b84c6
Update apps/managedidentity/managedidentity.go
4gust Nov 14, 2024
4735991
Update apps/managedidentity/managedidentity.go
4gust Nov 15, 2024
08353c9
Updated method name
4gust Nov 15, 2024
f3f3ea7
Updating the test to have original agent value
4gust Nov 15, 2024
c225221
Added a source based retry
4gust Nov 15, 2024
e5c8bc7
Updated status code list.
4gust Nov 15, 2024
4f3b414
Updated comment.
4gust Nov 15, 2024
2c6dfda
Merge pull request #533 from AzureAD/4ugust/azure-arc-branch
4gust Nov 18, 2024
191e9c2
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
4gust Nov 18, 2024
abf8b86
Updated retry code logic.
4gust Nov 19, 2024
1cd9908
Update apps/managedidentity/managedidentity.go
4gust Nov 21, 2024
73fda09
updated code for comments
4gust Nov 21, 2024
33386f0
Merge branch '4gust/mi-retry-policy' of https://github.com/AzureAD/mi…
4gust Nov 21, 2024
f8bd970
Added app service support
4gust Nov 25, 2024
d210244
updated comment
4gust Nov 25, 2024
23290c4
Updated tests
4gust Nov 25, 2024
a81a5be
Update apps/managedidentity/managedidentity_test.go
4gust Nov 26, 2024
86d023d
updated tests and comments
4gust Nov 26, 2024
d93e752
Merge branch '4gust/mi-retry-policy' of https://github.com/AzureAD/mi…
4gust Nov 26, 2024
3fd8ad5
Update managedidentity_test.go
4gust Nov 26, 2024
949376f
Merge pull request #521 from AzureAD/4gust/mi-retry-policy
4gust Nov 26, 2024
fedc34e
Update managedidentity.go
4gust Nov 26, 2024
a9e876f
Updated README about the Managed identity client usage
4gust Nov 26, 2024
509a187
Added logging
4gust Nov 28, 2024
0c4f0d2
Removed a potential leak
4gust Nov 28, 2024
cc4ca5a
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
4gust Nov 28, 2024
d52e165
Removed logger to have it own PR
4gust Nov 29, 2024
8c5b978
Updated request timeout to 60 seconds
4gust Nov 29, 2024
5aed02f
Updated for comments
4gust Dec 30, 2024
549b2b0
Updated Resource id parameter
4gust Dec 31, 2024
7ce51d1
Removed some unused parameters
4gust Dec 31, 2024
e6bf2b0
added support for the expires_on
4gust Jan 2, 2025
818cdc9
removed comments
4gust Jan 3, 2025
9484ecb
Added support for expires_in
4gust Jan 6, 2025
0bd7694
Revert "Added support for expires_in"
4gust Jan 7, 2025
cef9b0d
Updated expires_on
4gust Jan 7, 2025
c1f6fe7
now also supports unix time
4gust Jan 7, 2025
30fbff6
Updated the ExpiresOn for time.time
4gust Jan 8, 2025
72caa4b
added comment for time format in response issue
4gust Jan 8, 2025
98160b9
Update tokens.go
4gust Jan 8, 2025
6842852
Update apps/managedidentity/managedidentity.go
4gust Jan 15, 2025
1f333ee
* Add CloudShell Source
AndyOHart Jan 15, 2025
aebff8a
* Updates cloudshell request to use post and change how it works slig…
AndyOHart Jan 16, 2025
c4c322a
Logging
AndyOHart Jan 16, 2025
8e46939
* Updates retry function to save body correctly
AndyOHart Jan 16, 2025
8aec875
Test for user assigned
AndyOHart Jan 16, 2025
900b479
Set back to system assigned
AndyOHart Jan 16, 2025
6d80337
Apply suggestions from code review
4gust Jan 16, 2025
0d15af6
Added one more test for only expires_in
4gust Jan 16, 2025
2310106
Update managedidentity_test.go
4gust Jan 16, 2025
ca8ee6d
Updated time to check for unix time
4gust Jan 16, 2025
faf744d
Merge pull request #537 from AzureAD/4gust/appservice
4gust Jan 17, 2025
7a40af3
Update apps/managedidentity/cloudshell_service.go
AndyOHart Jan 20, 2025
9afad1c
* PR Comment changes
AndyOHart Jan 22, 2025
cd112b6
* Test updates
AndyOHart Jan 22, 2025
ca9eb2f
* Fix tests
AndyOHart Jan 22, 2025
3b4bcbe
PR Fix
AndyOHart Jan 22, 2025
4845578
Some pr changes
AndyOHart Jan 22, 2025
d476131
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
AndyOHart Jan 22, 2025
e181930
Fix
AndyOHart Jan 22, 2025
5f0512f
* Restores tests
AndyOHart Jan 23, 2025
895adad
* Remove saving body and use resource instead
AndyOHart Jan 23, 2025
2335b39
Remove sample changes
AndyOHart Jan 23, 2025
92fb4f2
Restore to previous way of handling user assigned id
AndyOHart Jan 23, 2025
3ed6adf
* remove unused code
AndyOHart Jan 23, 2025
9023ae8
* Revert retry
AndyOHart Jan 23, 2025
8167b8e
PR fixes
AndyOHart Jan 26, 2025
ed29784
* Add logic for getting using Azure ML source
AndyOHart Jan 28, 2025
4d8afe6
* Small pr fixes
AndyOHart Jan 28, 2025
31d4e16
Merge pull request #544 from AzureAD/cloudshell-service
AndyOHart Jan 28, 2025
acba4e4
* adds azure ml support
AndyOHart Jan 28, 2025
ed1b4b2
* Address PR comments
AndyOHart Jan 29, 2025
bdc08c4
* sets default client id
AndyOHart Jan 30, 2025
2d31094
* test for user assigned
AndyOHart Jan 30, 2025
27070b2
* test for user assigned
AndyOHart Jan 30, 2025
3072e45
* Revert changes
AndyOHart Jan 30, 2025
11b2940
* Update tests
AndyOHart Jan 31, 2025
3d24639
* Small pr fix
AndyOHart Jan 31, 2025
57ad23c
Merge pull request #546 from AzureAD/azure-ml
AndyOHart Jan 31, 2025
a0bb786
Support for ServiceFabric (#548)
4gust Feb 7, 2025
a20f226
Remove redundant ClientOptions type
chlowell Feb 12, 2025
9f23e44
Merge pull request #551 from AzureAD/chlowell/mi-options
AndyOHart Feb 13, 2025
f039f60
* Add managed identity tests for the pipeline
AndyOHart Feb 13, 2025
ee4aecf
Update .github/workflows/go.yml
AndyOHart Feb 14, 2025
b55d783
* Adds missing license headers
AndyOHart Feb 14, 2025
a7d6092
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
AndyOHart Feb 14, 2025
aa159ca
Update docs/managedidentity_public_api.md
AndyOHart Feb 14, 2025
30eccc4
* Remove sample app file
AndyOHart Feb 14, 2025
4f2685b
Merge branch 'andyohart/managed-identity' of https://github.com/Azure…
AndyOHart Feb 14, 2025
08a6e34
Added a new error InvalidJsonErr (#553)
4gust Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: go build ./apps/...

- name: Unit Tests
run: go test -race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/...
run: go test -race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/... ./apps/managedidentity/...
# Intergration tests runs on ADO
# - name: Integration Tests
# run: go test -race ./apps/tests/integration/...
Expand Down
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
57 changes: 46 additions & 11 deletions apps/confidential/confidential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/kylelemons/godebug/pretty"

"github.com/AzureAD/microsoft-authentication-library-for-go/apps/cache"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/exported"
internalTime "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json/types/time"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/mock"
Expand All @@ -35,6 +35,7 @@ import (

// errorClient is an HTTP client for tests that should fail when confidential.Client sends a request
type errorClient struct{}
type contextKey struct{}

func (*errorClient) Do(req *http.Request) (*http.Response, error) {
return nil, fmt.Errorf("expected no requests but received one for %s", req.URL.String())
Expand Down Expand Up @@ -138,7 +139,7 @@ func TestAcquireTokenByCredential(t *testing.T) {
}
client, err := fakeClient(accesstokens.TokenResponse{
AccessToken: token,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExpiresOn: time.Now().Add(1 * time.Hour),
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
TokenType: "Bearer",
Expand Down Expand Up @@ -290,7 +291,7 @@ func TestAcquireTokenOnBehalfOf(t *testing.T) {

func TestAcquireTokenByAssertionCallback(t *testing.T) {
calls := 0
key := struct{}{}
key := contextKey{}
ctx := context.WithValue(context.Background(), key, true)
getAssertion := func(c context.Context, o AssertionRequestOptions) (string, error) {
if v := c.Value(key); v == nil || !v.(bool) {
Expand Down Expand Up @@ -343,7 +344,7 @@ func TestAcquireTokenByAuthCode(t *testing.T) {
tr := accesstokens.TokenResponse{
AccessToken: token,
RefreshToken: refresh,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExpiresOn: time.Now().Add(1 * time.Hour),
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
IDToken: accesstokens.IDToken{
Expand Down Expand Up @@ -412,6 +413,40 @@ func TestAcquireTokenByAuthCode(t *testing.T) {
}
}

func TestInvalidJsonErrFromResponse(t *testing.T) {
cred, err := NewCredFromSecret(fakeSecret)
if err != nil {
t.Fatal(err)
}
tenant := "A"
lmo := "login.microsoftonline.com"
mockClient := mock.Client{}
mockClient.AppendResponse(mock.WithBody(mock.GetInstanceDiscoveryBody(lmo, tenant)))
client, err := New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient))
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
// cache an access token for each tenant. To simplify determining their provenance below, the value of each token is the ID of the tenant that provided it.
if _, err = client.AcquireTokenSilent(ctx, tokenScope, WithTenantID(tenant)); err == nil {
t.Fatal("silent auth should fail because the cache is empty")
}
mockClient.AppendResponse(mock.WithBody(mock.GetTenantDiscoveryBody(lmo, tenant)))
body := fmt.Sprintf(
`{"access_token": "%s","expires_in": %d,"expires_on": %d,"token_type": "Bearer"`,
tenant, 3600, time.Now().Add(time.Duration(3600)*time.Second).Unix(),
)
mockClient.AppendResponse(mock.WithBody([]byte(body)))
_, err = client.AcquireTokenByCredential(ctx, tokenScope, WithTenantID(tenant))
if err == nil {
t.Fatal("should have failed with InvalidJsonErr Response")
}
var ie errors.InvalidJsonErr
if !errors.As(err, &ie) {
t.Fatal("should have revieved a InvalidJsonErr, but got", err)
}
}

func TestAcquireTokenSilentTenants(t *testing.T) {
cred, err := NewCredFromSecret(fakeSecret)
if err != nil {
Expand Down Expand Up @@ -463,7 +498,7 @@ func TestADFSTokenCaching(t *testing.T) {
AccessToken: "at1",
RefreshToken: "rt",
TokenType: "bearer",
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
IDToken: accesstokens.IDToken{
Expand Down Expand Up @@ -593,7 +628,7 @@ func TestNewCredFromCert(t *testing.T) {
t.Run(fmt.Sprintf("%s/%v", filepath.Base(file.path), sendX5c), func(t *testing.T) {
client, err := fakeClient(accesstokens.TokenResponse{
AccessToken: token,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
}, cred, fakeAuthority, opts...)
if err != nil {
Expand Down Expand Up @@ -709,7 +744,7 @@ func TestNewCredFromTokenProvider(t *testing.T) {
expectedToken := "expected token"
called := false
expiresIn := 4200
key := struct{}{}
key := contextKey{}
ctx := context.WithValue(context.Background(), key, true)
cred := NewCredFromTokenProvider(func(c context.Context, tp exported.TokenProviderParameters) (exported.TokenProviderResult, error) {
if called {
Expand Down Expand Up @@ -965,7 +1000,7 @@ func TestWithClaims(t *testing.T) {
case "obo":
ar, err = client.AcquireTokenOnBehalfOf(ctx, "assertion", tokenScope, WithClaims(test.claims))
default:
t.Fatalf("test bug: no test for " + method)
t.Fatalf("test bug: no test for %s", method)
}
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1075,7 +1110,7 @@ func TestWithTenantID(t *testing.T) {
case "obo":
ar, err = client.AcquireTokenOnBehalfOf(ctx, "assertion", tokenScope, WithTenantID(test.tenant))
default:
t.Fatalf("test bug: no test for " + method)
t.Fatalf("test bug: no test for %s", method)
}
if err != nil {
if test.expectError {
Expand Down Expand Up @@ -1383,7 +1418,7 @@ func TestWithAuthenticationScheme(t *testing.T) {
}
client, err := fakeClient(accesstokens.TokenResponse{
AccessToken: token,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExpiresOn: time.Now().Add(1 * time.Hour),
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
TokenType: "TokenType",
Expand Down Expand Up @@ -1423,7 +1458,7 @@ func TestAcquireTokenByCredentialFromDSTS(t *testing.T) {
}
client, err := fakeClient(accesstokens.TokenResponse{
AccessToken: token,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
ExpiresOn: time.Now().Add(1 * time.Hour),
ExtExpiresOn: internalTime.DurationTime{T: time.Now().Add(1 * time.Hour)},
GrantedScopes: accesstokens.Scopes{Slice: tokenScope},
TokenType: "Bearer",
Expand Down
9 changes: 9 additions & 0 deletions apps/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ type CallErr struct {
Err error
}

type InvalidJsonErr struct {
Err error
}

// Errors implements error.Error().
func (e CallErr) Error() string {
return e.Err.Error()
}

// Errors implements error.Error().
func (e InvalidJsonErr) Error() string {
return e.Err.Error()
}

// Verbose prints a versbose error message with the request or response.
func (e CallErr) Verbose() string {
e.Resp.Request = nil // This brings in a bunch of TLS crap we don't need
Expand Down
5 changes: 2 additions & 3 deletions apps/internal/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/AzureAD/microsoft-authentication-library-for-go/apps/cache"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/base/internal/storage"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/base/storage"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/accesstokens"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority"
Expand Down Expand Up @@ -111,7 +111,6 @@ func AuthResultFromStorage(storageTokenResponse storage.TokenResponse) (AuthResu
if err := storageTokenResponse.AccessToken.Validate(); err != nil {
return AuthResult{}, fmt.Errorf("problem with access token in StorageTokenResponse: %w", err)
}

account := storageTokenResponse.Account
accessToken := storageTokenResponse.AccessToken.Secret
grantedScopes := strings.Split(storageTokenResponse.AccessToken.Scopes, scopeSeparator)
Expand Down Expand Up @@ -146,7 +145,7 @@ func NewAuthResult(tokenResponse accesstokens.TokenResponse, account shared.Acco
Account: account,
IDToken: tokenResponse.IDToken,
AccessToken: tokenResponse.AccessToken,
ExpiresOn: tokenResponse.ExpiresOn.T,
ExpiresOn: tokenResponse.ExpiresOn,
GrantedScopes: tokenResponse.GrantedScopes.Slice,
Metadata: AuthResultMetadata{
TokenSource: IdentityProvider,
Expand Down
12 changes: 6 additions & 6 deletions apps/internal/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/AzureAD/microsoft-authentication-library-for-go/apps/cache"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/base/internal/storage"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/base/storage"
internalTime "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json/types/time"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/fake"
Expand Down Expand Up @@ -50,7 +50,7 @@ func fakeClient(t *testing.T, opts ...Option) Client {
client.Token.AccessTokens = &fake.AccessTokens{
AccessToken: accesstokens.TokenResponse{
AccessToken: fakeAccessToken,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
FamilyID: "family-id",
GrantedScopes: accesstokens.Scopes{Slice: testScopes},
IDToken: fakeIDToken,
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestAcquireTokenSilentScopes(t *testing.T) {
accesstokens.TokenResponse{
AccessToken: fakeAccessToken,
ClientInfo: accesstokens.ClientInfo{UID: "uid", UTID: "utid"},
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(-time.Hour)},
ExpiresOn: time.Now().Add(-time.Hour),
GrantedScopes: accesstokens.Scopes{Slice: test.cachedTokenScopes},
IDToken: fakeIDToken,
RefreshToken: fakeRefreshToken,
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestAcquireTokenSilentGrantedScopes(t *testing.T) {
},
accesstokens.TokenResponse{
AccessToken: expectedToken,
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
GrantedScopes: accesstokens.Scopes{Slice: grantedScopes},
TokenType: "Bearer",
},
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestCreateAuthenticationResult(t *testing.T) {
desc: "no declined scopes",
input: accesstokens.TokenResponse{
AccessToken: "accessToken",
ExpiresOn: internalTime.DurationTime{T: future},
ExpiresOn: future,
GrantedScopes: accesstokens.Scopes{Slice: []string{"user.read"}},
DeclinedScopes: nil,
},
Expand All @@ -353,7 +353,7 @@ func TestCreateAuthenticationResult(t *testing.T) {
desc: "declined scopes",
input: accesstokens.TokenResponse{
AccessToken: "accessToken",
ExpiresOn: internalTime.DurationTime{T: future},
ExpiresOn: future,
GrantedScopes: accesstokens.Scopes{Slice: []string{"user.read"}},
DeclinedScopes: []string{"openid"},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func NewAccessToken(homeID, env, realm, clientID string, cachedAt, expiresOn, ex

// Key outputs the key that can be used to uniquely look up this entry in a map.
func (a AccessToken) Key() string {
ks := []string{a.HomeAccountID, a.Environment, a.CredentialType, a.ClientID, a.Realm, a.Scopes}
key := strings.Join(
[]string{a.HomeAccountID, a.Environment, a.CredentialType, a.ClientID, a.Realm, a.Scopes},
ks,
shared.CacheKeySeparator,
)
// add token type to key for new access tokens types. skip for bearer token type to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestContractUnmarshalJSON(t *testing.T) {
}
if diff := pretty.Compare(want, got); diff != "" {
t.Errorf("TestContractUnmarshalJSON: -want/+got:\n%s", diff)
t.Errorf(string(got.AdditionalFields["unknownEntity"].(stdJSON.RawMessage)))
t.Errorf("%s", string(got.AdditionalFields["unknownEntity"].(stdJSON.RawMessage)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (m *PartitionedManager) Write(authParameters authority.AuthParams, tokenRes
realm,
clientID,
cachedAt,
tokenResponse.ExpiresOn.T,
tokenResponse.ExpiresOn,
tokenResponse.ExtExpiresOn.T,
target,
tokenResponse.AccessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"
"time"

internalTime "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json/types/time"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/accesstokens"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/shared"
Expand Down Expand Up @@ -59,7 +58,7 @@ func TestOBOAccessTokenScopes(t *testing.T) {
accesstokens.TokenResponse{
AccessToken: scope[0] + "-at",
ClientInfo: accesstokens.ClientInfo{UID: upn, UTID: idt.TenantID},
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
GrantedScopes: accesstokens.Scopes{Slice: scope},
IDToken: idt,
RefreshToken: upn + "-rt",
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestOBOPartitioning(t *testing.T) {
accesstokens.TokenResponse{
AccessToken: upn + "-at",
ClientInfo: accesstokens.ClientInfo{UID: upn, UTID: idt.TenantID},
ExpiresOn: internalTime.DurationTime{T: time.Now().Add(time.Hour)},
ExpiresOn: time.Now().Add(time.Hour),
GrantedScopes: accesstokens.Scopes{Slice: scopes},
IDToken: idt,
RefreshToken: upn + "-rt",
Expand Down
Loading
Loading