diff --git a/lib/auth-service.d.ts b/lib/auth-service.d.ts index 881878b..0c1ddc9 100644 --- a/lib/auth-service.d.ts +++ b/lib/auth-service.d.ts @@ -74,7 +74,7 @@ export declare class AuthService implements IAuthService { protected onAuthorizationNotification( request: AuthorizationRequest, response: AuthorizationResponse | null, - error: AuthorizationError | null + error: AuthorizationError | null, ): void; protected internalAuthorizationCallback(url: string): Promise; protected internalEndSessionCallback(): Promise; diff --git a/lib/auth-service.js b/lib/auth-service.js index cfa7c77..ed19dee 100644 --- a/lib/auth-service.js +++ b/lib/auth-service.js @@ -170,20 +170,15 @@ export class AuthService { } performEndSessionRequest(state) { return __awaiter(this, void 0, void 0, function* () { - if (this._tokenSubject.value != undefined) { - let requestJson = { - postLogoutRedirectURI: this.authConfig.end_session_redirect_url, - idTokenHint: this._tokenSubject.value.idToken || '', - state: state || undefined, - }; - let request = new EndSessionRequest(requestJson); - let returnedUrl = yield this.endSessionHandler.performEndSessionRequest(yield this.configuration, request); - //callback may come from showWindow or via another method - if (returnedUrl != undefined) { - this.endSessionCallback(); - } - } else { - //if user has no token they should not be logged in in the first place + let requestJson = { + postLogoutRedirectURI: this.authConfig.end_session_redirect_url, + idTokenHint: this._tokenSubject.value ? this._tokenSubject.value.idToken || '' : '', + state: state || undefined, + }; + let request = new EndSessionRequest(requestJson); + let returnedUrl = yield this.endSessionHandler.performEndSessionRequest(yield this.configuration, request); + //callback may come from showWindow or via another method + if (returnedUrl != undefined) { this.endSessionCallback(); } }); @@ -226,8 +221,8 @@ export class AuthService { }); } requestTokenRefresh() { - var _a; return __awaiter(this, void 0, void 0, function* () { + var _a; if (!this._tokenSubject.value) { throw new Error('No Token Defined!'); } @@ -302,7 +297,10 @@ export class AuthService { if (revokeTokens) { yield this.revokeTokens(); } - yield this.storage.removeItem(TOKEN_RESPONSE_KEY); + const token = yield this.storage.getItem(TOKEN_RESPONSE_KEY); + if (token) { + yield this.storage.removeItem(TOKEN_RESPONSE_KEY); + } if ((yield this.configuration).endSessionEndpoint) { yield this.performEndSessionRequest(state).catch((response) => { this.notifyActionListers(AuthActionBuilder.SignOutFailed(response)); @@ -343,8 +341,8 @@ export class AuthService { this.notifyActionListers(AuthActionBuilder.SignOutFailed(response)); }); } - getValidToken(buffer = AUTH_EXPIRY_BUFFER) { - return __awaiter(this, void 0, void 0, function* () { + getValidToken() { + return __awaiter(this, arguments, void 0, function* (buffer = AUTH_EXPIRY_BUFFER) { if (this._tokenSubject.value) { if (!this._tokenSubject.value.isValid(buffer)) { yield this.refreshToken(); diff --git a/lib/cordova/cordova-secure-storage.js b/lib/cordova/cordova-secure-storage.js index 9f3de49..f1bd442 100644 --- a/lib/cordova/cordova-secure-storage.js +++ b/lib/cordova/cordova-secure-storage.js @@ -15,7 +15,7 @@ export class CordovaSecureStorage extends StorageBackend { yield CordovaDocument.ready(); return SecureStorage.create(this.KEYSTORE).then( () => true, - () => false + () => false, ); }); } diff --git a/package-lock.json b/package-lock.json index 73a7e00..dbcfc86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,14 @@ { "name": "ionic-appauth", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ionic-appauth", - "version": "2.0.0", + "version": "2.1.0", "license": "MIT", "dependencies": { - "@awesome-cordova-plugins/in-app-browser": "^6.3.0", "@openid/appauth": "^1.3.1", "@types/chai-as-promised": "^7.1.7", "tslib": "^2.6.2", diff --git a/package.json b/package.json index fc603a4..0271be5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ionic-appauth", - "version": "2.0.0", + "version": "2.1.0", "description": "Integration for OpenId/AppAuth-JS into Ionic", "main": "lib/index.js", "scripts": { diff --git a/src/auth-service.ts b/src/auth-service.ts index c887020..0717f8f 100644 --- a/src/auth-service.ts +++ b/src/auth-service.ts @@ -69,7 +69,7 @@ export class AuthService implements IAuthService { constructor( protected browser: Browser = new DefaultBrowser(), protected storage: StorageBackend = new LocalStorageBackend(), - protected requestor: Requestor = new JQueryRequestor() + protected requestor: Requestor = new JQueryRequestor(), ) { this.tokenHandler = new BaseTokenRequestHandler(requestor); this.userInfoHandler = new IonicUserInfoHandler(requestor); @@ -196,7 +196,7 @@ export class AuthService implements IAuthService { protected onAuthorizationNotification( request: AuthorizationRequest, response: AuthorizationResponse | null, - error: AuthorizationError | null + error: AuthorizationError | null, ) { let codeVerifier: string | undefined = request.internal != undefined && this.authConfig.pkce ? request.internal.code_verifier : undefined; @@ -223,7 +223,6 @@ export class AuthService implements IAuthService { } protected async performEndSessionRequest(state?: string): Promise { - let requestJson: EndSessionRequestJson = { postLogoutRedirectURI: this.authConfig.end_session_redirect_url, idTokenHint: this._tokenSubject.value ? this._tokenSubject.value.idToken || '' : '', @@ -236,7 +235,6 @@ export class AuthService implements IAuthService { if (returnedUrl != undefined) { this.endSessionCallback(); } - } protected async performAuthorizationRequest(authExtras?: StringMap, state?: string): Promise { @@ -350,7 +348,6 @@ export class AuthService implements IAuthService { } public async signOut(state?: string, revokeTokens?: boolean) { - if (revokeTokens) { await this.revokeTokens(); } diff --git a/src/authorization-request-handler.ts b/src/authorization-request-handler.ts index 7def1a9..9599a3f 100644 --- a/src/authorization-request-handler.ts +++ b/src/authorization-request-handler.ts @@ -29,7 +29,7 @@ export class IonicAuthorizationRequestHandler extends AuthorizationRequestHandle private browser: Browser, private storage: StorageBackend, utils = new BasicQueryStringUtils(), - private generateRandom = new DefaultCrypto() + private generateRandom = new DefaultCrypto(), ) { super(utils, generateRandom); } diff --git a/src/cordova/cordova-secure-storage.ts b/src/cordova/cordova-secure-storage.ts index 3288821..ed91806 100644 --- a/src/cordova/cordova-secure-storage.ts +++ b/src/cordova/cordova-secure-storage.ts @@ -12,7 +12,7 @@ export class CordovaSecureStorage extends StorageBackend { await CordovaDocument.ready(); return SecureStorage.create(this.KEYSTORE).then( () => true, - () => false + () => false, ); } diff --git a/src/end-session-request-handler.ts b/src/end-session-request-handler.ts index 4f8e13e..0458134 100644 --- a/src/end-session-request-handler.ts +++ b/src/end-session-request-handler.ts @@ -7,11 +7,14 @@ export interface EndSessionHandler { } export class IonicEndSessionHandler implements EndSessionHandler { - constructor(private browser: Browser, private utils = new BasicQueryStringUtils()) {} + constructor( + private browser: Browser, + private utils = new BasicQueryStringUtils(), + ) {} public async performEndSessionRequest( configuration: AuthorizationServiceConfiguration, - request: EndSessionRequest + request: EndSessionRequest, ): Promise { let url = this.buildRequestUrl(configuration, request); return this.browser.showWindow(url, request.postLogoutRedirectURI); diff --git a/test/unit/auth-service.spec.ts b/test/unit/auth-service.spec.ts index 83ec4ae..413a763 100644 --- a/test/unit/auth-service.spec.ts +++ b/test/unit/auth-service.spec.ts @@ -31,7 +31,7 @@ async function buildAuthServiceAndInit(withToken: boolean): Promise userinfo_endpoint: 'userinfo_endpointTest', }; when(mockedRequestorClass.xhr(anything())).thenReturn( - new Promise((resolve) => resolve(authServiceConfigJson)) + new Promise((resolve) => resolve(authServiceConfigJson)), ); const mockedRequestor = instance(mockedRequestorClass); diff --git a/test/unit/authorization-request-handler.spec.ts b/test/unit/authorization-request-handler.spec.ts index eb45396..f7804a3 100644 --- a/test/unit/authorization-request-handler.spec.ts +++ b/test/unit/authorization-request-handler.spec.ts @@ -34,12 +34,12 @@ async function performIonicRequestHandlerAuthReq(url: string | undefined, mocked mockedBrowser, storage, undefined, - crypto + crypto, ); await ionicAuthorizationRequestHandler.performAuthorizationRequest( mockedAuthorizationServiceConfiguration, - new AuthorizationRequest(authRequestJson, crypto, false) + new AuthorizationRequest(authRequestJson, crypto, false), ); return storage.getItem(AUTHORIZATION_RESPONSE_KEY); diff --git a/test/unit/capacitor/capacitor-secure-storage.spec.ts b/test/unit/capacitor/capacitor-secure-storage.spec.ts index 14a4e5c..403306f 100644 --- a/test/unit/capacitor/capacitor-secure-storage.spec.ts +++ b/test/unit/capacitor/capacitor-secure-storage.spec.ts @@ -22,7 +22,7 @@ describe('capacitor secure storage Tests', () => { new Promise((resolve, reject) => { resolve(value); reject(null); - }) + }), ); storage.getItem(KEY).then((returnedValue) => { expect(returnedValue).to.be.equal(value); diff --git a/test/unit/end-session-request-handler.spec.ts b/test/unit/end-session-request-handler.spec.ts index 0822f0f..5c2497d 100644 --- a/test/unit/end-session-request-handler.spec.ts +++ b/test/unit/end-session-request-handler.spec.ts @@ -25,7 +25,7 @@ describe('end Session request handler Tests', () => { const ionicEndSessionHandler: IonicEndSessionHandler = new IonicEndSessionHandler(mockedBrowser); const urlResult = await ionicEndSessionHandler.performEndSessionRequest( mockedAuthorizationServiceConfiguration, - mockedEndSessionRequest + mockedEndSessionRequest, ); expect(urlResult).to.equal(returnedUrl); });