Skip to main content

@idpass/data-collect-core / OtpAuthAdapter

Class: OtpAuthAdapter

Defined in: components/authentication/OtpAuthAdapter.ts:42

Authentication adapter that uses one-time passwords (OTP) sent to a phone number or email address. Designed for self-service access by beneficiaries who may not have traditional login credentials.

Flow:

  1. Call requestOtp(identifier) to send a 6-digit code
  2. Call verifyOtp(identifier, otp) to exchange the code for a JWT
  3. The JWT has scope "self-service" and is scoped to the beneficiary's entity

Implements

Constructors

Constructor

new OtpAuthAdapter(storage, config): OtpAuthAdapter

Defined in: components/authentication/OtpAuthAdapter.ts:45

Parameters

storage

SingleAuthStorage | null

config

AuthConfig

Returns

OtpAuthAdapter

Methods

requestOtp()

requestOtp(identifier): Promise<{ success: boolean; expiresIn: number; }>

Defined in: components/authentication/OtpAuthAdapter.ts:53

Request OTP to be sent to phone/email

Parameters

identifier

string

Returns

Promise<{ success: boolean; expiresIn: number; }>


verifyOtp()

verifyOtp(identifier, otp): Promise<{ username: string; token: string; }>

Defined in: components/authentication/OtpAuthAdapter.ts:69

Verify OTP and get token

Parameters

identifier

string

otp

string

Returns

Promise<{ username: string; token: string; }>


isAuthenticated()

isAuthenticated(): Promise<boolean>

Defined in: components/authentication/OtpAuthAdapter.ts:92

Check if currently authenticated

Returns

Promise<boolean>

Implementation of

AuthAdapter.isAuthenticated


validateToken()

validateToken(token): Promise<boolean>

Defined in: components/authentication/OtpAuthAdapter.ts:104

Validate stored token

Parameters

token

string

Returns

Promise<boolean>

Implementation of

AuthAdapter.validateToken


logout()

logout(): Promise<void>

Defined in: components/authentication/OtpAuthAdapter.ts:118

Returns

Promise<void>

Implementation of

AuthAdapter.logout


initialize()

initialize(): Promise<void>

Defined in: components/authentication/OtpAuthAdapter.ts:124

Returns

Promise<void>

Implementation of

AuthAdapter.initialize


login()

login(_credentials): Promise<{ username: string; token: string; }>

Defined in: components/authentication/OtpAuthAdapter.ts:128

Parameters

_credentials

PasswordCredentials | TokenCredentials | null

Returns

Promise<{ username: string; token: string; }>

Implementation of

AuthAdapter.login


handleCallback()

handleCallback(): Promise<void>

Defined in: components/authentication/OtpAuthAdapter.ts:134

Returns

Promise<void>

Implementation of

AuthAdapter.handleCallback