-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to specify oidc token audience (#75)
* Add ability to specify oidc token audience; Closes #65 * Move logic inside `createOIDCToken`
- Loading branch information
1 parent
c86b917
commit 903e095
Showing
3 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import ( | |
) | ||
|
||
func TestCreateOIDCTokenSetsCorrectData(t *testing.T) { | ||
tokenStr := createOIDCToken("[email protected]", "http://my.service/foo?bar=v") | ||
tokenStr := createOIDCToken("[email protected]", "http://my.service/foo?bar=v", "") | ||
parser := new(jwt.Parser) | ||
token, _, err := parser.ParseUnverified(tokenStr, &OpenIDConnectClaims{}) | ||
require.NoError(t, err) | ||
|
@@ -33,9 +33,28 @@ func TestCreateOIDCTokenSetsCorrectData(t *testing.T) { | |
assertRoughTimestamp(t, 5*time.Minute, claims.ExpiresAt, "Expires in 5 mins") | ||
} | ||
|
||
func TestCreateOIDCTokenWithCustomAudienceSetsCorrectData(t *testing.T) { | ||
tokenStr := createOIDCToken("[email protected]", "http://my.service/foo?bar=v", "http://my.api") | ||
parser := new(jwt.Parser) | ||
token, _, err := parser.ParseUnverified(tokenStr, &OpenIDConnectClaims{}) | ||
require.NoError(t, err) | ||
assert.Equal(t, "RS256", token.Header["alg"], "Uses RS256") | ||
assert.Equal(t, OpenIDConfig.KeyID, token.Header["kid"], "Specifies kid") | ||
|
||
claims := token.Claims.(*OpenIDConnectClaims) | ||
|
||
assert.Equal(t, "http://my.api", claims.Audience, "Specifies audience") | ||
assert.Equal(t, OpenIDConfig.IssuerURL, claims.Issuer, "Specifies issuer") | ||
assert.Equal(t, "[email protected]", claims.Email, "Specifies email") | ||
assert.True(t, claims.EmailVerified, "Specifies email") | ||
assertRoughTimestamp(t, 0*time.Second, claims.IssuedAt, "Issued now") | ||
assertRoughTimestamp(t, 0*time.Second, claims.NotBefore, "Not before now") | ||
assertRoughTimestamp(t, 5*time.Minute, claims.ExpiresAt, "Expires in 5 mins") | ||
} | ||
|
||
func TestCreateOIDCTokenSignatureIsValidAgainstKey(t *testing.T) { | ||
// Sanity check that the token is valid if we have the private key in go format | ||
tokenStr := createOIDCToken("[email protected]", "http://any.service/foo") | ||
tokenStr := createOIDCToken("[email protected]", "http://any.service/foo", "") | ||
_, err := new(jwt.Parser).ParseWithClaims( | ||
tokenStr, | ||
&OpenIDConnectClaims{}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters