Options
All
  • Public
  • Public/Protected
  • All
Menu

Client for the PCon Login OAuth API

Hierarchy

  • PConLoginClient

Index

Constructors

constructor

  • Constructor for the login client.

    Parameters

    • oauthOptions: OAuthOptions

      Contains the parameters provided to the OAuth API

    • Optional pconLoginURLS: Partial<PConLoginURLs>

    Returns PConLoginClient

Properties

options

options: OAuthOptions

OAuth Options set for the client

Methods

fetchWithAuth

  • fetchWithAuth(resource: string | Request, init?: RequestInit): Promise<null | Response>
  • Thin wrapper around the built-in browser function fetch(), that adds the appropriate "Authorization" header necessary for calls to pCon.login

    Please refer to the documentation of fetch() for more details on parameters and the return value. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

    Parameters

    • resource: string | Request

      The resource you want to fetch. Either the URL as string, or a Request object

    • Optional init: RequestInit

      An object containing any custom settings that you want to apply to the request.

    Returns Promise<null | Response>

    Promise, resolves to null if there is no valid access token and login process should be triggered. else returns Promise returned by fetch

getAccessToken

  • getAccessToken(force_new?: boolean): Promise<null | string>
  • Obtain a valid access token. Unless the optional parameter "force_new" is true, this may be a previously cached token. If the returned Promise resolves to null, the application should display the user an appropriate error dialog and restart the login process to obtain valid tokens again.

    Parameters

    • force_new: boolean = false

      If true, always refreshes token beforehand

    Returns Promise<null | string>

    Access token, if available, else null

getAppData

  • getAppData(): null | string
  • Gets user data stored when logging in.

    Returns null | string

getAuthorizationURI

  • getAuthorizationURI(): Promise<URL>
  • Generate Authorization URI for login. Can be used to create your own URI to redirect to or to open in Popup.

    Returns Promise<URL>

handlePopupFinished

  • handlePopupFinished(): void
  • This should be called after handleRedirect finished, i.e. the returned promise resolved without error. This will make the access token available in your application.

    Returns void

handleRedirect

  • handleRedirect(): Promise<void>
  • This should be called from your redirect URI, after the authorization API endpoint has redirected you to your redirect_uri you set in the constructor. If you

    This will handle the parameters provided by the authorization API and obtain the access token.

    The returned promise will resolve, after the access token has been obtained.

    throws

    {OAuthError} Will throw an error if:

    • No values for PKCE are available in session storage
    • Authorization Code is not available in query params from redirect
    • State is not available in query params
    • State doesn't match the randomly generated state

    Returns Promise<void>

    Returns the Promise received by the fetch call after parsing the access token

isAccessTokenValid

  • isAccessTokenValid(): boolean
  • Checks if an access token is available and if it has expired.

    This is only deducted from information locally available, without a call to the server. It is possible the access token has been invalidated externally, e.g. if the user logs out from elsewhere or by changing password.

    Returns boolean

    true, if access token is valid, false if not

loginWithRedirect

  • loginWithRedirect(next?: string, appData?: string): Promise<void>
  • Start login process by redirecting the browser to the authorization endpoint.

    NOTE: This means the current state of the page will be lost!

    Parameters

    • Optional next: string

      The page you want to redirect to using redirectToNext. If this parameter is not provided, the library will set the "next" location to the current window.location

    • Optional appData: string

      The application data you want to store until after the login process. Will be available after authorization using getAppData

    Returns Promise<void>

logout

  • logout(next?: string): void
  • Revokes access/refresh tokens and logs the user out from pCon.

    NOTE: As the logout process involves a redirect, the page state will be lost.

    If you want the user to return to your application after the logout you can pass an appropriate URL as the "next" parameter.

    Parameters

    • Optional next: string

      Page to redirect to after logging out

    Returns void

redirectToNext

  • redirectToNext(): void
  • Redirects to next parameter. If next parameter was specified in loginWithRedirect, it's redirected there, else it will redirect to the location loginWithRedirect was called from.

    Returns void

revokeToken

  • revokeToken(): Promise<void>
  • Revoke access token. Unlike logout, this will only revoke the token, and not logout the user session.

    NOTE: Usually you will want to call logout instead of this function.

    Returns Promise<void>

    Promise returned by the fetch call to /revoke_tokens

Generated using TypeDoc