Home Reference Source
import SalteAuth from '@salte-auth/salte-auth'
public class | source

SalteAuth

Authentication Controller

Constructor Summary

Public Constructor
public

constructor(config: Config)

Sets up Salte Auth

Member Summary

Public Members
public

mixin: *

A mixin built for Web Components

public

The user profile for salte auth

Method Summary

Public Methods
public

Registers a timeout that will automatically refresh the id token

public

Authenticates using the iframe-based OAuth flow.

public

Authenticates using the tab-based OAuth flow.

public

Authenticates using the popup-based OAuth flow.

public

Authenticates using the redirect-based OAuth flow.

public

Unauthenticates using the iframe-based OAuth flow.

public

Unauthenticates using the tab-based OAuth flow.

public

Unauthenticates using the popup-based OAuth flow.

public

Logs the user out of their configured identity provider.

public

off(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function)

Deregister a callback previously registered.

public

on(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function)

Listens for an event to be invoked.

public

Refreshes the users tokens and renews their session.

public

Authenticates, requests the access token, and returns it if necessary.

Public Constructors

public constructor(config: Config) source

Sets up Salte Auth

Params:

NameTypeAttributeDescription
config Config

configuration for salte auth

Public Members

public mixin: * source

A mixin built for Web Components

Example:

class MyElement extends auth.mixin(HTMLElement) {
  constructor() {
    super();

    console.log(this.auth); // This is the same as auth
    console.log(this.user); // This is the same as auth.profile.userInfo.
    console.log(this.authenticated); // This is the same as auth.profile.idTokenExpired.
  }
}

public profile: SalteAuthProfile source

The user profile for salte auth

Public Methods

public $$refreshToken() source

Registers a timeout that will automatically refresh the id token

public loginWithIframe(config: Boolean | LoginConfig): Promise<Object> source

Authenticates using the iframe-based OAuth flow.

Params:

NameTypeAttributeDescription
config Boolean | LoginConfig

Whether this request is intended to refresh the token.

Return:

Promise<Object>

a promise that resolves when we finish authenticating

Example:

auth.loginWithIframe().then((user) => {
  console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public loginWithNewTab(): Promise<Object> source

Authenticates using the tab-based OAuth flow.

Return:

Promise<Object>

a promise that resolves when we finish authenticating

Example:

auth.loginWithNewTab().then((user) => {
  console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public loginWithPopup(): Promise<Object> source

Authenticates using the popup-based OAuth flow.

Return:

Promise<Object>

a promise that resolves when we finish authenticating

Example:

auth.loginWithPopup().then((user) => {
  console.log(user); // This is the same as auth.profile.userInfo.
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public loginWithRedirect(redirectUrl: String): Promise source

Authenticates using the redirect-based OAuth flow.

Params:

NameTypeAttributeDescription
redirectUrl String

override for the redirect url, by default this will try to redirect the user back where they started.

Return:

Promise

a promise intended to block future login attempts.

Example:

auth.loginWithRedirect(); // Don't bother with utilizing the promise here, it never resolves.

public logoutWithIframe(): Promise source

Unauthenticates using the iframe-based OAuth flow.

Return:

Promise

a promise that resolves when we finish deauthenticating

Example:

auth.logoutWithIframe().then(() => {
  console.log('success!');
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public logoutWithNewTab(): Promise source

Unauthenticates using the tab-based OAuth flow.

Return:

Promise

a promise that resolves when we finish deauthenticating

Example:

auth.logoutWithNewTab().then(() => {
  console.log('success!');
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public logoutWithPopup(): Promise source

Unauthenticates using the popup-based OAuth flow.

Return:

Promise

a promise that resolves when we finish deauthenticating

Example:

auth.logoutWithPopup().then(() => {
  console.log('success!');
}).catch((error) => {
  console.error('Whoops something went wrong!', error);
});

public logoutWithRedirect() source

Logs the user out of their configured identity provider.

Example:

auth.logoutWithRedirect();

public off(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function) source

Deregister a callback previously registered.

Params:

NameTypeAttributeDescription
eventType 'login' | 'logout' | 'refresh' | 'expired'

the event to deregister.

callback Function

A callback that fires when the specified event occurs.

Example:

const someFunction = function() {};

auth.on('login', someFunction);

auth.off('login', someFunction);

public on(eventType: 'login' | 'logout' | 'refresh' | 'expired', callback: Function) source

Listens for an event to be invoked.

Params:

NameTypeAttributeDescription
eventType 'login' | 'logout' | 'refresh' | 'expired'

the event to listen for.

callback Function

A callback that fires when the specified event occurs.

Example:

auth.on('login', (error, user) => {
  if (error) {
    console.log('something bad happened!');
  }

  console.log(user); // This is the same as auth.profile.userInfo.
});
window.addEventListener('salte-auth-login', (event) => {
  if (event.detail.error) {
    console.log('something bad happened!');
  }

  console.log(event.detail.data); // This is the same as auth.profile.userInfo.
});

public refreshToken(): Promise source

Refreshes the users tokens and renews their session.

Return:

Promise

a promise that resolves when we finish renewing the users tokens.

public retrieveAccessToken(): Promise<string> source

Authenticates, requests the access token, and returns it if necessary.

Return:

Promise<string>

a promise that resolves when we retrieve the access token