Web JS SDK

Install web-js NPM

Install web-js to your web app.

npm i @axioms/web-js

Basic Uusage

Create Axioms auth object,

import { Auth } from '@axioms/web-js';
const $auth = new Auth({
axioms_domain: '<Your-Axioms-Domain>',
response_type: '<Your-Response-Type>',
redirect_uri: 'https://<Your-App-Host>/callback',
post_logout_uri: 'https://<Your-App-Host>/login',
client_id: '<Your-Client-ID>',
scope: '<Your-Scope>',
post_login_navigate: '<Your-Post-Login-Navigate>'
});
ParameterAllowed value/sRequired
axioms_domainyour tenant's primary or custom domain without protocol i.e. your-slug.us.axioms.io or auth.my-domain.comYes
response_typeSupported values code (authorization code flow)or id_token token (implicit code flow)
redirect_uriredirect_uri registered in your Client's settings area in your tenant's control planeYes
post_logout_uripost_logout_uri registered in your Client's settings area in your tenant's control planeYes
scopeSpace separated scopes values . Bare-minimum you need openid. If you need user profile and email to be included in issued id_token then your scope should look like openid profile email. See list of all supported scopes hereYes
post_login_navigateApplication path where user should be navigated after successful login. For example, /home or /dashboardYes

Web-js API

Function/ObjectDescription
$auth.login_with_redirect()Login user with redirect to Axioms hosted login page
$auth.login_with_email_link(email)Passwordless login using magic link sent to email address of the user
$auth.logout_with_redirect()Logout user with redirect to Axioms logout endpoint
$auth.session.is_authenticated()Check if user session is authenticated or not
$auth.get_user_settings_url()Get user settings URL where user can update profile, password, multi-factor preferences, sessions and apps.
$auth.session.id_payloadGet payload of id token and access individual attributes by name
$auth.session.id_tokenGet id token for the session
$auth.session.access_tokenGet access token for the session (if included in response type)
$auth.session.hasRole(required_roles)Check any of the required roles included in roles claim of the id token. required_roles must be an array of strings with each string representing a role.
$auth.session.hasScope(required_scopes)Check any of the required scopes included in scope claim of the id token. required_scopes must be an array of strings with each string representing a scope.
$auth.session.hasPermission(required_permissions)Check any of the required permissions included in permissions claim of the id token. required_permissions must be an array of strings with each string representing a permission.