Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Update AuthJS dependency (#263)
Browse files Browse the repository at this point in the history
* Updates libs to use AuthJS 2.0
* Increment package versions and update changelings
* Update wait times in vie tests, these tests appear to be affected by the new async nature of the token getter
  • Loading branch information
jmelberg-okta authored and robertdamphousse-okta committed Aug 16, 2018
1 parent 2e251da commit 2928b1f
Show file tree
Hide file tree
Showing 19 changed files with 4,017 additions and 588 deletions.
6 changes: 6 additions & 0 deletions packages/okta-angular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.3

### Other

- Updated `@okta/okta-auth-js` dependency to version 2.

# 1.0.2

### Other
Expand Down
14 changes: 10 additions & 4 deletions packages/okta-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/okta-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@okta/okta-angular",
"version": "1.0.2",
"version": "1.0.3",
"description": "Angular support for Okta",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
],
"license": "Apache-2.0",
"dependencies": {
"@okta/okta-auth-js": "^1.14.0"
"@okta/okta-auth-js": "^2.0.0"
},
"devDependencies": {
"@angular/common": "^4.4.3",
Expand Down
9 changes: 4 additions & 5 deletions packages/okta-angular/src/okta/services/okta.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class OktaAuthService {
this.observers = [];

this.oktaAuth = new OktaAuth({
url: auth.issuer.split('/oauth2/')[0],
clientId: auth.clientId,
issuer: auth.issuer,
redirectUri: auth.redirectUri
Expand Down Expand Up @@ -89,15 +88,15 @@ export class OktaAuthService {
* Returns the current accessToken in the tokenManager.
*/
async getAccessToken(): Promise<string | undefined> {
const accessToken = this.oktaAuth.tokenManager.get('accessToken');
const accessToken = await this.oktaAuth.tokenManager.get('accessToken');
return accessToken ? accessToken.accessToken : undefined;
}

/**
* Returns the current idToken in the tokenManager.
*/
async getIdToken(): Promise<string | undefined> {
const idToken = this.oktaAuth.tokenManager.get('idToken');
const idToken = await this.oktaAuth.tokenManager.get('idToken');
return idToken ? idToken.idToken : undefined;
}

Expand All @@ -106,8 +105,8 @@ export class OktaAuthService {
* accessToken is provided or parses the available idToken.
*/
async getUser(): Promise<UserClaims|undefined> {
const accessToken = this.oktaAuth.tokenManager.get('accessToken');
const idToken = this.oktaAuth.tokenManager.get('idToken');
const accessToken = await this.oktaAuth.tokenManager.get('accessToken');
const idToken = await this.oktaAuth.tokenManager.get('idToken');
if (accessToken && idToken) {
const userinfo = await this.oktaAuth.token.getUserInfo(accessToken);
if (userinfo.sub === idToken.claims.sub) {
Expand Down
18 changes: 12 additions & 6 deletions packages/okta-angular/test/e2e/harness/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/okta-angular/test/e2e/harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@angular/platform-browser": "^6.0.7",
"@angular/platform-browser-dynamic": "^6.0.7",
"@angular/router": "^6.0.7",
"@okta/okta-angular": "file:../../../okta-okta-angular-1.0.1.tgz",
"@okta/okta-angular": "file:../../../okta-okta-angular-1.0.2.tgz",
"core-js": "^2.4.1",
"ejs": "^2.5.6",
"rxjs": "^6.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('Unit Tests', () => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
localStorage.clear();
});

it('should create the app', async(() => {
Expand All @@ -52,4 +53,37 @@ describe('Unit Tests', () => {
expect(config.scope).toBe('email openid');
expect(config.responseType).toBe('id_token');
}));

it('can retrieve an accessToken from the tokenManager', async (done) => {
const mockAccessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXIiOj' +
'EsImp0aSI6IkFULnJ2Ym5TNGlXdTJhRE5jYTNid1RmMEg5Z' +
'VdjV2xsS1FlaU5ZX1ZlSW1NWkEiLCJpc3MiOiJodHRwczov' +
'L2xib3lldHRlLnRyZXhjbG91ZC5jb20vYXMvb3JzMXJnM3p' +
'5YzhtdlZUSk8wZzciLCJhdWQiOiJodHRwczovL2xib3lldH' +
'RlLnRyZXhjbG91ZC5jb20vYXMvb3JzMXJnM3p5YzhtdlZUS' +
'k8wZzciLCJzdWIiOiIwMHUxcGNsYTVxWUlSRURMV0NRViIs' +
'ImlhdCI6MTQ2ODQ2NzY0NywiZXhwIjoxNDY4NDcxMjQ3LCJ' +
'jaWQiOiJQZjBhaWZyaFladTF2MFAxYkZGeiIsInVpZCI6Ij' +
'AwdTFwY2xhNXFZSVJFRExXQ1FWIiwic2NwIjpbIm9wZW5pZ' +
'CIsImVtYWlsIl19.ziKfS8IjSdOdTHCZllTDnLFdE96U9bS' +
'IsJzI0MQ0zlnM2QiiA7nvS54k6Xy78ebnkJvmeMCctjXVKk' +
'JOEhR6vs11qVmIgbwZ4--MqUIRU3WoFEsr0muLl039QrUa1' +
'EQ9-Ua9rPOMaO0pFC6h2lfB_HfzGifXATKsN-wLdxk6cgA';
const standardAccessTokenParsed = {
accessToken: mockAccessToken,
expiresAt: new Date().getTime() + 100, // ensure token is active
scopes: ['openid', 'email'],
tokenType: 'Bearer',
authorizeUrl: environment.ISSUER + '/oauth2/v1/authorize',
userinfoUrl: environment.ISSUER + '/oauth2/v1/userinfo'
};
// Store the token
localStorage.setItem(
'okta-token-storage',
JSON.stringify({'accessToken': standardAccessTokenParsed}),
);
const accessToken = await component.oktaAuth.getAccessToken();
expect(accessToken).toBe(mockAccessToken);
done();
});
});
5 changes: 5 additions & 0 deletions packages/okta-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 1.0.3

### Other

- Updated `@okta/okta-auth-js` dependency to version 2.
14 changes: 10 additions & 4 deletions packages/okta-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/okta-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@okta/okta-react",
"version": "1.0.2",
"version": "1.0.3",
"description": "React support for Okta",
"main": "./dist/index.js",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://github.com/okta/okta-oidc-js#readme",
"dependencies": {
"@okta/okta-auth-js": "^1.14.0",
"@okta/okta-auth-js": "^2.0.0",
"babel-runtime": "^6.26.0",
"prop-types": "^15.5.10"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/okta-react/src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default class Auth {
}

async getUser() {
const accessToken = this._oktaAuth.tokenManager.get('accessToken');
const idToken = this._oktaAuth.tokenManager.get('idToken');
const accessToken = await this._oktaAuth.tokenManager.get('accessToken');
const idToken = await this._oktaAuth.tokenManager.get('idToken');
if (accessToken && idToken) {
const userinfo = await this._oktaAuth.token.getUserInfo(accessToken);
if (userinfo.sub === idToken.claims.sub) {
Expand All @@ -71,12 +71,12 @@ export default class Auth {
}

async getIdToken() {
const idToken = this._oktaAuth.tokenManager.get('idToken');
const idToken = await this._oktaAuth.tokenManager.get('idToken');
return idToken ? idToken.idToken : undefined;
}

async getAccessToken() {
const accessToken = this._oktaAuth.tokenManager.get('accessToken');
const accessToken = await this._oktaAuth.tokenManager.get('accessToken');
return accessToken ? accessToken.accessToken : undefined;
}

Expand Down
49 changes: 47 additions & 2 deletions packages/okta-react/test/jest/auth.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
import Auth from '../../src/Auth';

import AuthJS from '@okta/okta-auth-js'
const pkg = require('../../package.json');

jest.mock('@okta/okta-auth-js');

const mockAccessToken = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXIiOj' +
'EsImp0aSI6IkFULnJ2Ym5TNGlXdTJhRE5jYTNid1RmMEg5Z' +
'VdjV2xsS1FlaU5ZX1ZlSW1NWkEiLCJpc3MiOiJodHRwczov' +
'L2xib3lldHRlLnRyZXhjbG91ZC5jb20vYXMvb3JzMXJnM3p' +
'5YzhtdlZUSk8wZzciLCJhdWQiOiJodHRwczovL2xib3lldH' +
'RlLnRyZXhjbG91ZC5jb20vYXMvb3JzMXJnM3p5YzhtdlZUS' +
'k8wZzciLCJzdWIiOiIwMHUxcGNsYTVxWUlSRURMV0NRViIs' +
'ImlhdCI6MTQ2ODQ2NzY0NywiZXhwIjoxNDY4NDcxMjQ3LCJ' +
'jaWQiOiJQZjBhaWZyaFladTF2MFAxYkZGeiIsInVpZCI6Ij' +
'AwdTFwY2xhNXFZSVJFRExXQ1FWIiwic2NwIjpbIm9wZW5pZ' +
'CIsImVtYWlsIl19.ziKfS8IjSdOdTHCZllTDnLFdE96U9bS' +
'IsJzI0MQ0zlnM2QiiA7nvS54k6Xy78ebnkJvmeMCctjXVKk' +
'JOEhR6vs11qVmIgbwZ4--MqUIRU3WoFEsr0muLl039QrUa1' +
'EQ9-Ua9rPOMaO0pFC6h2lfB_HfzGifXATKsN-wLdxk6cgA';

const standardAccessTokenParsed = {
accessToken: mockAccessToken,
expiresAt: new Date().getTime() + 100, // ensure token is active
scopes: ['openid', 'email'],
tokenType: 'Bearer',
authorizeUrl: 'https://foo/oauth2/v1/authorize',
userinfoUrl: 'https://foo/oauth2/v1/userinfo'
};

const mockAuthJsInstance = {
userAgent: 'okta-auth-js',
tokenManager: {
get: jest.fn().mockReturnValue(Promise.resolve(standardAccessTokenParsed))
}
};

AuthJS.mockImplementation(() => {
return mockAuthJsInstance
});

test('Auth component sets the right user agent on AuthJS', () => {
const auth = new Auth({
issuer: 'https://foo/oauth2/default'
});
const expectedUserAgent = `${pkg.name}/${pkg.version} okta-auth-js-`;
const expectedUserAgent = `${pkg.name}/${pkg.version} okta-auth-js`;
expect(auth._oktaAuth.userAgent).toMatch(expectedUserAgent);
});
test('Auth component can retrieve an accessToken from the tokenManager', async (done) => {
const auth = new Auth({
issuer: 'https://foo/oauth2/default'
});
const accessToken = await auth.getAccessToken();
expect(accessToken).toBe(mockAccessToken);
done();
});
5 changes: 5 additions & 0 deletions packages/okta-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 1.0.2

### Other

- Updated `@okta/okta-auth-js` dependency to version 2.
Loading

0 comments on commit 2928b1f

Please sign in to comment.