mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
feat: add auth support (default and paia)
This commit is contained in:
committed by
Jovan Krunić
parent
046a95ba1d
commit
b5f239ea4e
53
src/app/modules/auth/default-auth.service.ts
Normal file
53
src/app/modules/auth/default-auth.service.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import {AuthorizationRequestHandler} from '@openid/appauth';
|
||||
import {
|
||||
StorageBackend,
|
||||
Requestor,
|
||||
AuthorizationServiceConfiguration,
|
||||
LocalStorageBackend,
|
||||
JQueryRequestor,
|
||||
TokenRequestHandler,
|
||||
} from '@openid/appauth';
|
||||
import {
|
||||
UserInfoHandler,
|
||||
EndSessionHandler,
|
||||
Browser,
|
||||
DefaultBrowser,
|
||||
AuthService,
|
||||
AuthActionBuilder,
|
||||
} from 'ionic-appauth';
|
||||
|
||||
const TOKEN_RESPONSE_KEY = 'token_response';
|
||||
|
||||
export class DefaultAuthService extends AuthService {
|
||||
public localConfiguration: AuthorizationServiceConfiguration;
|
||||
|
||||
protected tokenHandler: TokenRequestHandler;
|
||||
|
||||
protected userInfoHandler: UserInfoHandler;
|
||||
|
||||
protected requestHandler: AuthorizationRequestHandler;
|
||||
|
||||
protected endSessionHandler: EndSessionHandler;
|
||||
|
||||
constructor(
|
||||
protected browser: Browser = new DefaultBrowser(),
|
||||
protected storage: StorageBackend = new LocalStorageBackend(),
|
||||
protected requestor: Requestor = new JQueryRequestor(),
|
||||
) {
|
||||
super(browser, storage, requestor);
|
||||
}
|
||||
|
||||
get configuration(): Promise<AuthorizationServiceConfiguration> {
|
||||
if (!this.localConfiguration)
|
||||
throw new Error('Local Configuration Not Defined');
|
||||
|
||||
return Promise.resolve(this.localConfiguration);
|
||||
}
|
||||
|
||||
public async signOut() {
|
||||
await this.storage.removeItem(TOKEN_RESPONSE_KEY).catch(error => {
|
||||
this.notifyActionListers(AuthActionBuilder.SignOutFailed(error));
|
||||
});
|
||||
this.notifyActionListers(AuthActionBuilder.SignOutSuccess());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user