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

feat: Support custom claims in AccessToken - OKTA-326437 #518

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.3.0

### Features
- [#518](https://github.com/okta/okta-auth-js/pull/518) Added `claims` to `AccessToken`

## 4.2.0

### Features
Expand Down
8 changes: 5 additions & 3 deletions lib/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ function handleOAuthResponse(sdk: OktaAuth, tokenParams: TokenParams, res: OAuth
var refreshToken = res.refresh_token;

if (accessToken) {
var accessJwt = sdk.token.decode(accessToken);
tokenDict.accessToken = {
value: accessToken,
accessToken: accessToken,
claims: accessJwt.payload,
expiresAt: Number(expiresIn) + Math.floor(Date.now() / 1000),
tokenType: tokenType,
scopes: scopes,
Expand All @@ -295,13 +297,13 @@ function handleOAuthResponse(sdk: OktaAuth, tokenParams: TokenParams, res: OAuth
}

if (idToken) {
var jwt = sdk.token.decode(idToken);
var idJwt = sdk.token.decode(idToken);

var idTokenObj: IDToken = {
value: idToken,
idToken: idToken,
claims: jwt.payload,
expiresAt: jwt.payload.exp,
claims: idJwt.payload,
expiresAt: idJwt.payload.exp,
scopes: scopes,
authorizeUrl: urls.authorizeUrl,
issuer: urls.issuer,
Expand Down
1 change: 1 addition & 0 deletions lib/types/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface AbstractToken {

export interface AccessToken extends AbstractToken {
accessToken: string;
claims: UserClaims;
tokenType: string;
userinfoUrl: string;
}
Expand Down
2 changes: 1 addition & 1 deletion test/karma/spec/renewToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Renew token', function() {
redirectUri: REDIRECT_URI,
};

const ACCESS_TOKEN_STR = 'fakeytoken'; // will not be verified in this flow
const ACCESS_TOKEN_STR = tokens.standardAccessToken;
const ID_TOKEN_STR = tokens.standardIdToken;
const ACCCESS_TOKEN_PARSED = tokens.standardAccessTokenParsed;
const NONCE = tokens.standardIdTokenClaims.nonce;
Expand Down
3 changes: 3 additions & 0 deletions test/spec/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function setupSync(options?) {
function createAccessToken(strValue): AccessToken {
return {
accessToken: strValue,
claims: {
sub: ''
},
value: strValue,
userinfoUrl: '',
authorizeUrl: '',
Expand Down
34 changes: 34 additions & 0 deletions test/support/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,26 @@ tokens.standardAccessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXIiOj' +
'JOEhR6vs11qVmIgbwZ4--MqUIRU3WoFEsr0muLl039QrUa1' +
'EQ9-Ua9rPOMaO0pFC6h2lfB_HfzGifXATKsN-wLdxk6cgA';

tokens.standardAccessTokenClaims = {
'aud': 'https://lboyette.trexcloud.com/as/ors1rg3zyc8mvVTJO0g7',
'cid': 'Pf0aifrhYZu1v0P1bFFz',
'exp': 1468471247,
'iat': 1468467647,
'iss': 'https://lboyette.trexcloud.com/as/ors1rg3zyc8mvVTJO0g7',
'jti': 'AT.rvbnS4iWu2aDNca3bwTf0H9eWcWllKQeiNY_VeImMZA',
'scp': [
'openid',
'email',
],
'sub': '00u1pcla5qYIREDLWCQV',
'uid': '00u1pcla5qYIREDLWCQV',
'ver': 1,
};

tokens.standardAccessTokenParsed = {
value: tokens.standardAccessToken,
accessToken: tokens.standardAccessToken,
claims: tokens.standardAccessTokenClaims,
expiresAt: 1449703529, // assuming time = 1449699929
scopes: ['openid', 'email'],
tokenType: 'Bearer',
Expand All @@ -270,9 +287,26 @@ tokens.authServerAccessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXIiOjE
'EE8wXbgYjzGH5T6dazwgGfGmVf2PTa1pKfPew7f_XKE_t1O_tJ9C' +
'h9gY9Z3xd92ac407ZIOHkabLvZ0-45ANM3Gm0LC0c';

tokens.authServerAccessTokenClaims = {
'ver': 1,
'jti': 'AT._0Y3BbEy_f42ScS2VOwksTp8B8QojYS3bMtXCDFrxh8',
'iss': 'https://auth-js-test.okta.com/oauth2/aus8aus76q8iphupD0h7',
'aud': 'http://example.com',
'sub': 'samljackson@okta.com',
'iat': 1449699929,
'exp': 1449703529,
'cid': 'gLzF0DhjQIGCT4qO0SMB',
'uid': '00ukoeEqIogiFHpDe0g3',
'scp': [
'openid',
'email',
],
};

tokens.authServerAccessTokenParsed = {
value: tokens.authServerAccessToken,
accessToken: tokens.authServerAccessToken,
claims: tokens.authServerAccessTokenClaims,
expiresAt: 1449703529, // assuming time = 1449699929
scopes: ['openid', 'email'],
tokenType: 'Bearer',
Expand Down