Helper class to integrate Fief authentication in a browser application.

Example

const fiefClient = new fief.Fief({
baseURL: 'https://example.fief.dev',
clientId: 'YOUR_CLIENT_ID',
});
const fiefAuth = new fief.browser.FiefAuth(fiefClient);

Hierarchy

  • FiefAuth

Constructors

Properties

client: Fief
pendingAuthCallbacks: Set<string>

Methods

  • Complete the Fief authentication process by exchanging the authorization code available in query parameters and store the tokens and user information in the browser session.

    Under the hood, it automatically handles the PKCE code challenge.

    Parameters

    • redirectURI: string

      The exact same redirectURI you passed to the authorization URL.

    Returns Promise<void>

  • Return the token information object available in session, or null if no current session.

    Returns null | FiefTokenResponse

    The token information, or null if not available.

    Example

    const tokenInfo = fiefAuth.getTokenInfo();
    
  • Return the user information object available in session, or null if no current session.

    Returns null | FiefUserInfo

    The user information, or null if not available.

    Example

    const userinfo = fiefAuth.getUserinfo();
    
  • Return whether there is a valid user session in the browser.

    Returns boolean

    true if there is a valid user session, false otherwise.

    Example

    const isAuthenticated = fiefAuth.isAuthenticated();
    
  • Clear the access token and the user information from the browser storage and redirect to the Fief logout endpoint.

    Parameters

    • redirectURI: string

      A valid URL where the user will be redirected after the logout process.

    Returns Promise<void>

    Example

    fiefAuth.logout('http://localhost:8080')
    
  • Start a Fief authorization process and perform the redirection.

    Under the hood, it automatically handles the PKCE code challenge.

    Parameters

    • redirectURI: string

      Your callback URI where the user will be redirected after Fief authentication.

    • Optional parameters: {
          extrasParams?: Record<string, string>;
          lang?: string;
          scope?: string[];
          state?: string;
      }
      • Optional extrasParams?: Record<string, string>

        Optional object containing specific parameters.

      • Optional lang?: string

        Optional parameter to set the user locale. Should be a valid RFC 3066 language identifier, like fr or pt-PT.

      • Optional scope?: string[]

        Optional list of scopes to ask for. Defaults to ['openid'].

      • Optional state?: string

        Optional string that will be returned back in the callback parameters to allow you to retrieve state information.

    Returns Promise<void>

    Example

    fiefAuth.redirectToLogin('http://localhost:8080/callback.html');
    

    Example

    Set the user locale.

    fiefAuth.redirectToLogin('http://localhost:8080/callback.html', { lang: 'fr-FR' });
    
  • Refresh user information from the Fief API using the access token available in session.

    The fresh user information is returned and automatically updated in the session storage.

    Returns Promise<FiefUserInfo>

    The refreshed user information

    Example

    fiefAuth.refreshUserinfo()
    .then((userinfo) => {
    console.log(userinfo);
    })
    .catch((err) => {
    if (err instance of fief.browser.FiefAuthNotAuthenticatedError) {
    console.error('User is not logged in');
    }
    })
    ;

Generated using TypeDoc