UNPKG

@asgardeo/auth-angular

Version:
89 lines (88 loc) 3.96 kB
/** * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ import { Observable } from "rxjs"; import { OnDestroy } from "@angular/core"; import { AuthClientConfig, FetchResponse } from "@asgardeo/auth-spa"; import { AuthAngularConfig, AuthStateInterface } from "../models"; import { BasicUserInfo, CustomGrantConfig, DecodedIDTokenPayload, Hooks, HttpRequestConfig, HttpResponse, OIDCEndpoints, SignInConfig } from "../models/asgardeo-spa.models"; import { AsgardeoNavigatorService } from "./asgardeo-navigator.service"; import { AsgardeoAuthStateStoreService } from "./asgardeo-auth-state-store.service"; export declare class AsgardeoAuthService implements OnDestroy { private authConfig; private navigator; private stateStore; readonly state$: Observable<AuthStateInterface>; private auth; private readonly config; private subscriptionDestroyer$; constructor(authConfig: AuthClientConfig<AuthAngularConfig>, navigator: AsgardeoNavigatorService, stateStore: AsgardeoAuthStateStoreService); /** * Runs on service unmount. * @remarks Housekeeping logic such as un-subscribing should go here. */ ngOnDestroy(): void; /** * Registering a sign-out hook clears user session data internally if there was a successful logout. */ initializeHooks(): void; signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string): Promise<BasicUserInfo>; signInWithRedirect(): Promise<boolean>; signOut(): Promise<boolean>; isAuthenticated(): Promise<boolean>; getBasicUserInfo(): Promise<BasicUserInfo>; getAccessToken(): Promise<string>; getIDToken(): Promise<string>; getDecodedIDToken(): Promise<DecodedIDTokenPayload>; getOIDCServiceEndpoints(): Promise<OIDCEndpoints>; refreshAccessToken(): Promise<BasicUserInfo>; revokeAccessToken(): Promise<boolean>; on(hook: Hooks, callback: (response?: any) => void, id?: string): Promise<void>; requestCustomGrant(config: CustomGrantConfig): Promise<FetchResponse<any> | BasicUserInfo>; httpRequest(config: HttpRequestConfig): Promise<HttpResponse<any>>; httpRequestAll(config: HttpRequestConfig[]): Promise<HttpResponse<any>[]>; /** * This method allows you to sign in silently. * First, this method sends a prompt none request to see if there is an active user session in the identity server. * If there is one, then it requests the access token and stores it. Else, it returns false. * * @return {Promise<BasicUserInfo | boolean>} - A Promise that resolves with the user information after signing in * or with `false` if the user is not signed in. * * @example *``` * this.auth.trySignInSilently() *``` */ trySignInSilently: () => Promise<BasicUserInfo | boolean>; /** * Handles auto login by trying to exchange tokens if auth params i.e `code` and `session_state` is * available in the URL or else, tries to silently login. * * @private * @return {Observable<BasicUserInfo | boolean>} */ private handleAutoLogin; /** * Handles single logout if a prompt none sign in response is received with an error parameter on the URL. * * @private * @return {Promise<BasicUserInfo | void>} */ private handleSingleLogoutOnRedirect; }