Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed May 29, 2024
1 parent 1a4c3fa commit 70dc983
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/auth-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
protected internalEndSessionCallback(): Promise<void>;
Expand Down
34 changes: 16 additions & 18 deletions lib/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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!');
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/cordova/cordova-secure-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CordovaSecureStorage extends StorageBackend {
yield CordovaDocument.ready();
return SecureStorage.create(this.KEYSTORE).then(
() => true,
() => false
() => false,
);
});
}
Expand Down
5 changes: 2 additions & 3 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 2 additions & 5 deletions src/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -223,7 +223,6 @@ export class AuthService implements IAuthService {
}

protected async performEndSessionRequest(state?: string): Promise<void> {

let requestJson: EndSessionRequestJson = {
postLogoutRedirectURI: this.authConfig.end_session_redirect_url,
idTokenHint: this._tokenSubject.value ? this._tokenSubject.value.idToken || '' : '',
Expand All @@ -236,7 +235,6 @@ export class AuthService implements IAuthService {
if (returnedUrl != undefined) {
this.endSessionCallback();
}

}

protected async performAuthorizationRequest(authExtras?: StringMap, state?: string): Promise<void> {
Expand Down Expand Up @@ -350,7 +348,6 @@ export class AuthService implements IAuthService {
}

public async signOut(state?: string, revokeTokens?: boolean) {

if (revokeTokens) {
await this.revokeTokens();
}
Expand Down
2 changes: 1 addition & 1 deletion src/authorization-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cordova/cordova-secure-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CordovaSecureStorage extends StorageBackend {
await CordovaDocument.ready();
return SecureStorage.create(this.KEYSTORE).then(
() => true,
() => false
() => false,
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/end-session-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined> {
let url = this.buildRequestUrl(configuration, request);
return this.browser.showWindow(url, request.postLogoutRedirectURI);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/auth-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function buildAuthServiceAndInit(withToken: boolean): Promise<AuthService>
userinfo_endpoint: 'userinfo_endpointTest',
};
when(mockedRequestorClass.xhr<AuthorizationServiceConfigurationJson>(anything())).thenReturn(
new Promise((resolve) => resolve(authServiceConfigJson))
new Promise((resolve) => resolve(authServiceConfigJson)),
);
const mockedRequestor = instance(mockedRequestorClass);

Expand Down
4 changes: 2 additions & 2 deletions test/unit/authorization-request-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/capacitor/capacitor-secure-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/end-session-request-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 70dc983

Please sign in to comment.