Skip to main content

WebContainer

@authgear/web


@authgear/web / WebContainer

Class: WebContainer

WebContainer is the entrypoint of the SDK. An instance of a container allows the user to authenticate, reauthenticate, etc.

Every container has a name. The default name of a container is default. If your app supports multi login sessions, you can use multiple containers with different names. You are responsible for managing the list of names in this case.

Constructors

Constructor

new WebContainer(options?): WebContainer

Parameters

options?

ContainerOptions

Returns

WebContainer

Properties

delegate?

optional delegate: WebContainerDelegate


sessionType

sessionType: "cookie" | "refresh_token"

Accessors

accessToken

Get Signature

get accessToken(): string | undefined

Returns

string | undefined

Set Signature

set accessToken(accessToken): void

Parameters
accessToken

string | undefined

Returns

void


clientID

Get Signature

get clientID(): string | undefined

OIDC client ID

Returns

string | undefined

Set Signature

set clientID(clientID): void

Parameters
clientID

string | undefined

Returns

void


isSSOEnabled

Get Signature

get isSSOEnabled(): boolean

Is SSO enabled

Returns

boolean

Set Signature

set isSSOEnabled(isSSOEnabled): void

Parameters
isSSOEnabled

boolean

Returns

void


name

Get Signature

get name(): string

Unique ID for this container.

Default Value
"default"

@public
Returns

string

Set Signature

set name(name): void

Parameters
name

string

Returns

void


sessionState

Get Signature

get sessionState(): SessionState

Returns

SessionState

Set Signature

set sessionState(sessionState): void

Parameters
sessionState

SessionState

Returns

void

Methods

authenticateAnonymously()

authenticateAnonymously(): Promise<AuthenticateResult>

Authenticate as an anonymous user.

Returns

Promise<AuthenticateResult>


canReauthenticate()

canReauthenticate(): boolean

canReauthenticate() reports whether the current user can reauthenticate. The information comes from the ID token and the ID token is NOT verified.

Returns

boolean


configure()

configure(options): Promise<void>

configure() configures the container with the client ID and the endpoint. It also does local IO to retrieve the refresh token. It only obtains the refresh token locally and no network call will be triggered. So the session state maybe outdated for some reason, e.g. user session is revoked. fetchUserInfo should be called to obtain the latest user session state.

configure() can be called more than once if it failed. Otherwise, it is NOT recommended to call it more than once.

Parameters

options

ConfigureOptions

Returns

Promise<void>


fetch()

fetch(input, init?): Promise<Response>

Fetch function for you to call your application server. The fetch function will include Authorization header in your application request, and handle refresh access token automatically.

Parameters

input

RequestInfo | URL

init?

RequestInit

Returns

Promise<Response>


fetchUserInfo()

fetchUserInfo(): Promise<UserInfo>

Fetch user info.

Returns

Promise<UserInfo>


finishAddEmail()

finishAddEmail(): Promise<void>

Finish settings action "add_email".

It may reject with OAuthError.

Returns

Promise<void>


finishAddPhone()

finishAddPhone(): Promise<void>

Finish settings action "add_phone".

It may reject with OAuthError.

Returns

Promise<void>


finishAddUsername()

finishAddUsername(): Promise<void>

Finish settings action "add_username".

It may reject with OAuthError.

Returns

Promise<void>


finishAuthentication()

finishAuthentication(): Promise<AuthenticateResult>

Finish authentication.

It may reject with OAuthError.

Returns

Promise<AuthenticateResult>


finishChangeEmail()

finishChangeEmail(): Promise<void>

Finish settings action "change_email".

It may reject with OAuthError.

Returns

Promise<void>


finishChangePassword()

finishChangePassword(): Promise<void>

Finish settings action "change_password".

It may reject with OAuthError.

Returns

Promise<void>


finishChangePhone()

finishChangePhone(): Promise<void>

Finish settings action "change_phone".

It may reject with OAuthError.

Returns

Promise<void>


finishChangeUsername()

finishChangeUsername(): Promise<void>

Finish settings action "change_username".

It may reject with OAuthError.

Returns

Promise<void>


finishDeleteAccount()

finishDeleteAccount(): Promise<void>

Finish settings action "delete_account".

It may reject with OAuthError.

Returns

Promise<void>


finishLinkOAuth()

finishLinkOAuth(): Promise<void>

Finish settings action "link_oauth".

It may reject with OAuthError.

Returns

Promise<void>


finishPromoteAnonymousUser()

finishPromoteAnonymousUser(): Promise<ReauthenticateResult>

Finish promote anonymous user.

It may reject with OAuthError.

Returns

Promise<ReauthenticateResult>


finishReauthentication()

finishReauthentication(): Promise<ReauthenticateResult>

Finish reauthentication.

It may reject with OAuthError.

Returns

Promise<ReauthenticateResult>


finishUnlinkOAuth()

finishUnlinkOAuth(): Promise<void>

Finish settings action "unlink_oauth".

It may reject with OAuthError.

Returns

Promise<void>


getAuthTime()

getAuthTime(): Date | undefined

getAuthTime() reports the last time the user was authenticated. The information comes from the ID token and the ID token is NOT verified.

Returns

Date | undefined


getIDTokenHint()

getIDTokenHint(): string | undefined

getIDTokenHint() returns the ID token for the OIDC id_token_hint parameter.

Returns

string | undefined


logout()

logout(options?): Promise<void>

Logout.

Parameters

options?

Logout options

force?

boolean

redirectURI

string

Returns

Promise<void>

Remarks

If force parameter is set to true, all potential errors (e.g. network error) would be ignored.

redirectURI is required. User will be redirected to the uri after they have logged out.


makeAuthorizeURL()

makeAuthorizeURL(options): Promise<string>

Make authorize URL makes authorize URL based on options.

This function will be used if developer wants to redirection in their own code.

Parameters

options

AuthenticateOptions

Returns

Promise<string>


open()

open(page, options?): Promise<void>

Parameters

page

Page

options?

SettingOptions

Returns

Promise<void>


refreshAccessTokenIfNeeded()

refreshAccessTokenIfNeeded(): Promise<void>

Returns

Promise<void>


refreshIDToken()

refreshIDToken(): Promise<void>

refreshIDToken() asks the server to issue an ID token with latest claims. After refreshing, getIDTokenHint() and canReauthenticate() may return up-to-date value.

Returns

Promise<void>


startAddEmail()

startAddEmail(options): Promise<void>

Start settings action "add_email" by redirecting to the authorization endpoint.

Parameters

options

SettingsActionOptions

Returns

Promise<void>


startAddPhone()

startAddPhone(options): Promise<void>

Start settings action "add_phone" by redirecting to the authorization endpoint.

Parameters

options

SettingsActionOptions

Returns

Promise<void>


startAddUsername()

startAddUsername(options): Promise<void>

Start settings action "add_username" by redirecting to the authorization endpoint.

Parameters

options

SettingsActionOptions

Returns

Promise<void>


startAuthentication()

startAuthentication(options): Promise<void>

Start authentication by redirecting to the authorization endpoint.

Parameters

options

AuthenticateOptions

Returns

Promise<void>


startChangeEmail()

startChangeEmail(originalEmail, options): Promise<void>

Start settings action "change_email" by redirecting to the authorization endpoint.

Parameters

originalEmail

string

options

SettingsActionOptions

Returns

Promise<void>


startChangePassword()

startChangePassword(options): Promise<void>

Start settings action "change_password" by redirecting to the authorization endpoint.

Parameters

options

SettingsActionOptions

Returns

Promise<void>


startChangePhone()

startChangePhone(originalPhone, options): Promise<void>

Start settings action "change_phone" by redirecting to the authorization endpoint.

Parameters

originalPhone

string

options

SettingsActionOptions

Returns

Promise<void>


startChangeUsername()

startChangeUsername(originalUsername, options): Promise<void>

Start settings action "change_username" by redirecting to the authorization endpoint.

Parameters

originalUsername

string

options

SettingsActionOptions

Returns

Promise<void>


startDeleteAccount()

startDeleteAccount(options): Promise<void>

Start settings action "delete_account" by redirecting to the authorization endpoint.

Parameters

options

SettingsActionOptions

Returns

Promise<void>


startLinkOAuth()

startLinkOAuth(options): Promise<void>

Start settings action "link_oauth" by redirecting to the authorization endpoint.

Parameters

options

LinkOAuthOptions

Returns

Promise<void>


startPromoteAnonymousUser()

startPromoteAnonymousUser(options): Promise<void>

Start promote anonymous user by redirecting to the authorization endpoint.

Parameters

options

PromoteOptions

Returns

Promise<void>


startReauthentication()

startReauthentication(options): Promise<void>

Start reauthentication by redirecting to the authorization endpoint.

Parameters

options

ReauthenticateOptions

Returns

Promise<void>


startUnlinkOAuth()

startUnlinkOAuth(options): Promise<void>

Start settings action "unlink_oauth" by redirecting to the settings page.

Parameters

options

UnlinkOAuthOptions

Returns

Promise<void>