Skip to content

Commit

Permalink
Merge pull request #27 from microsoft/feat/add-context-param
Browse files Browse the repository at this point in the history
Pass context object to authorization method
  • Loading branch information
baywet authored Aug 31, 2022
2 parents 12fe247 + d5566c5 commit e955bc9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

.idea
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.4.0] - 2022-08-31

### Changed

- Pass `context.Context` for on `GetAuthorizationToken` method.

## [0.3.1] - 2022-06-07

### Changed
Expand Down
4 changes: 2 additions & 2 deletions azure_identity_access_token_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewAzureIdentityAccessTokenProviderWithScopesAndValidHosts(credential azcor
const claimsKey = "claims"

// GetAuthorizationToken returns the access token for the provided url.
func (p *AzureIdentityAccessTokenProvider) GetAuthorizationToken(url *u.URL, additionalAuthenticationContext map[string]interface{}) (string, error) {
func (p *AzureIdentityAccessTokenProvider) GetAuthorizationToken(ctx context.Context, url *u.URL, additionalAuthenticationContext map[string]interface{}) (string, error) {
if !(*(p.allowedHostsValidator)).IsUrlHostValid(url) {
return "", nil
}
Expand All @@ -84,7 +84,7 @@ func (p *AzureIdentityAccessTokenProvider) GetAuthorizationToken(url *u.URL, add
Scopes: p.scopes,
//TODO pass the claims once the API is updated to support it https://github.com/Azure/azure-sdk-for-go/issues/14284
}
token, err := p.credential.GetToken(context.Background(), options)
token, err := p.credential.GetToken(ctx, options)
if err != nil {
return "", err
}
Expand Down
10 changes: 5 additions & 5 deletions azure_identity_access_token_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAddsTokenOnValidHost(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, provider)

token, err := provider.GetAuthorizationToken(&u.URL{Host: "graph.microsoft.com", Scheme: "https"}, nil)
token, err := provider.GetAuthorizationToken(context.Background(), &u.URL{Host: "graph.microsoft.com", Scheme: "https"}, nil)
assert.Nil(t, err)
assert.Equal(t, "token", token)
}
Expand All @@ -38,7 +38,7 @@ func TestAddsTokenOnValidHostFromParse(t *testing.T) {
url, err := u.Parse("https://graph.microsoft.com")
assert.Nil(t, err)

token, err := provider.GetAuthorizationToken(url, nil)
token, err := provider.GetAuthorizationToken(context.Background(), url, nil)
assert.Nil(t, err)
assert.Equal(t, "token", token)
}
Expand All @@ -48,7 +48,7 @@ func TestDoesntAddTokenOnDifferentHost(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, provider)

token, err := provider.GetAuthorizationToken(&u.URL{Host: "differenthost.com"}, nil)
token, err := provider.GetAuthorizationToken(context.Background(), &u.URL{Host: "differenthost.com"}, nil)
assert.Nil(t, err)
assert.Empty(t, token)
}
Expand All @@ -58,7 +58,7 @@ func TestDoesntAddTokenOnHttp(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, provider)

token, err := provider.GetAuthorizationToken(&u.URL{Host: "differenthost.com", Scheme: "http"}, nil)
token, err := provider.GetAuthorizationToken(context.Background(), &u.URL{Host: "differenthost.com", Scheme: "http"}, nil)
assert.Nil(t, err)
assert.Empty(t, token)
}
Expand All @@ -73,7 +73,7 @@ func TestAddsClaimsToTokenRequest(t *testing.T) {

additionalContext := make(map[string]interface{})
additionalContext["claims"] = "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTY1MjgxMzUwOCJ9fX0="
token, err := provider.GetAuthorizationToken(url, additionalContext)
token, err := provider.GetAuthorizationToken(context.Background(), url, additionalContext)
assert.NotNil(t, err) //TODO update when azure identity has added the field
assert.Empty(t, token)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.2
github.com/microsoft/kiota-abstractions-go v0.8.2
github.com/microsoft/kiota-abstractions-go v0.9.0
github.com/stretchr/testify v1.8.0
)

Expand All @@ -14,7 +14,7 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/microsoft/kiota-abstractions-go v0.8.2 h1:KxHr72YwlntvVgF0C+8CtNmNQajtIq7fedq2N0+74Uk=
github.com/microsoft/kiota-abstractions-go v0.8.2/go.mod h1:i1wK2rdsLGSjgpnpLHjC60nEa/UdCVS6ulCh1Q+1COw=
github.com/microsoft/kiota-abstractions-go v0.9.0 h1:HqqC/vFGMO1XHQmkicVkMUGdQc2poLr3ynijQ/2PrTk=
github.com/microsoft/kiota-abstractions-go v0.9.0/go.mod h1:i1wK2rdsLGSjgpnpLHjC60nEa/UdCVS6ulCh1Q+1COw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -19,8 +19,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down

0 comments on commit e955bc9

Please sign in to comment.