Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AuthService<TAppState>

Type parameters

Hierarchy

  • AuthService

Implements

  • OnDestroy

Index

Constructors

constructor

Properties

Readonly appState$

appState$: Observable<TAppState> = ...

Emits the value (if any) that was passed to the loginWithRedirect method call but only after handleRedirectCallback is first called

Readonly error$

error$: Observable<Error> = ...

Emits errors that occur during login, or when checking for an active session on startup.

Readonly idTokenClaims$

idTokenClaims$: Observable<undefined | null | IdToken> = ...

Emits ID token claims when authenticated, or null if not authenticated.

Readonly isAuthenticated$

isAuthenticated$: Observable<boolean> = ...

Emits boolean values indicating the authentication state of the user. If true, it means a user has authenticated. This depends on the value of isLoading$, so there is no need to manually check the loading state of the SDK.

Readonly isLoading$

isLoading$: Observable<boolean> = ...

Emits boolean values indicating the loading state of the SDK.

Readonly user$

user$: Observable<undefined | null | User> = ...

Emits details about the authenticated user, or null if not authenticated.

Methods

buildAuthorizeUrl

  • buildAuthorizeUrl(options?: RedirectLoginOptions<any>): Observable<string>
  • buildAuthorizeUrl().subscribe(url => ...)
    

    Builds an /authorize URL for loginWithRedirect using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated.

    Parameters

    • Optional options: RedirectLoginOptions<any>

      The options

    Returns Observable<string>

    A URL to the authorize endpoint

buildLogoutUrl

  • buildLogoutUrl(options?: LogoutUrlOptions): Observable<string>
  • buildLogoutUrl().subscribe(url => ...)
    

    Builds a URL to the logout endpoint.

    Parameters

    • Optional options: LogoutUrlOptions

      The options used to configure the parameters that appear in the logout endpoint URL.

    Returns Observable<string>

    a URL to the logout endpoint using the parameters provided as arguments.

getAccessTokenSilently

  • getAccessTokenSilently(options: GetTokenSilentlyOptions & { detailedResponse: true }): Observable<GetTokenSilentlyVerboseResponse>
  • getAccessTokenSilently(options?: GetTokenSilentlyOptions): Observable<string>
  • Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.

    Parameters

    • options: GetTokenSilentlyOptions & { detailedResponse: true }

      The options for configuring the token fetch.

    Returns Observable<GetTokenSilentlyVerboseResponse>

  • Fetches a new access token and returns it.

    Parameters

    • Optional options: GetTokenSilentlyOptions

      The options for configuring the token fetch.

    Returns Observable<string>

getAccessTokenWithPopup

  • getAccessTokenWithPopup(options?: GetTokenWithPopupOptions): Observable<string>
  • getTokenWithPopup(options).subscribe(token => ...)
    

    Get an access token interactively.

    Opens a popup with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

    Parameters

    • Optional options: GetTokenWithPopupOptions

    Returns Observable<string>

getIdTokenClaims

  • getIdTokenClaims(options?: GetIdTokenClaimsOptions): Observable<undefined | IdToken>
  • getIdTokenClaims(options).subscribe(claims => ...);
    

    Returns all claims from the id_token if available.

    If you provide an audience or scope, they should match an existing Access Token (the SDK stores a corresponding ID Token with every Access Token, and uses the scope and audience to look up the ID Token)

    remarks

    The returned observable will emit once and then complete.

    Parameters

    • Optional options: GetIdTokenClaimsOptions

      The options to get the Id token claims

    Returns Observable<undefined | IdToken>

getUser

  • getUser<TUser>(options?: GetUserOptions): Observable<undefined | TUser>
  • getUser(options).subscribe(user => ...);
    

    Returns the user information if available (decoded from the id_token).

    If you provide an audience or scope, they should match an existing Access Token (the SDK stores a corresponding ID Token with every Access Token, and uses the scope and audience to look up the ID Token)

    remarks

    The returned observable will emit once and then complete.

    Type parameters

    • TUser: User<TUser>

      The type to return, has to extend {@link User}.

    Parameters

    • Optional options: GetUserOptions

      The options to get the user

    Returns Observable<undefined | TUser>

handleRedirectCallback

  • handleRedirectCallback(url?: string): Observable<RedirectLoginResult<TAppState>>
  • handleRedirectCallback(url).subscribe(result => ...)
    

    After the browser redirects back to the callback page, call handleRedirectCallback to handle success and error responses from Authok. If the response is successful, results will be valid according to their expiration times.

    Calling this method also refreshes the authentication and user states.

    Parameters

    • Optional url: string

      The URL to that should be used to retrieve the state and code values. Defaults to window.location.href if not given.

    Returns Observable<RedirectLoginResult<TAppState>>

loginWithPopup

  • loginWithPopup(options?: PopupLoginOptions, config?: PopupConfigOptions): Observable<void>
  • await loginWithPopup(options);
    

    Opens a popup with the /authorize URL using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.

    IMPORTANT: This method has to be called from an event handler that was started by the user like a button click, for example, otherwise the popup will be blocked in most browsers.

    Parameters

    • Optional options: PopupLoginOptions

      The login options

    • Optional config: PopupConfigOptions

      Configuration for the popup window

    Returns Observable<void>

loginWithRedirect

  • loginWithRedirect(options?: RedirectLoginOptions<TAppState>): Observable<void>
  • loginWithRedirect(options);
    

    Performs a redirect to /authorize using the parameters provided as arguments. Random and secure state and nonce parameters will be auto-generated.

    Parameters

    • Optional options: RedirectLoginOptions<TAppState>

      The login options

    Returns Observable<void>

logout

  • logout(options?: LogoutOptions): void
  • logout();
    

    Clears the application session and performs a redirect to /v1/logout, using the parameters provided as arguments, to clear the Authok session. If the federated option is specified it also clears the Identity Provider session. If the localOnly option is specified, it only clears the application session. It is invalid to set both the federated and localOnly options to true, and an error will be thrown if you do. Read more about how Logout works at Authok.

    Parameters

    • Optional options: LogoutOptions

      The logout options

    Returns void

ngOnDestroy

  • ngOnDestroy(): void
  • Called when the service is destroyed

    Returns void