Edit this page

UAuth JS Library

The @uauth/js library is the core UAuth library for single-page applications. It manages login sessions with the Uauth Service and provides a login popup flow built with React.

Client

The Client class is the default export for the @uauth/js package.

constructor

Copy
Copied
constructor(options: ClientOptions)

const uauth = new Client(options);

login()

Initiates UAuth authentication with an auth server redirect and callback flow. When using this method, the redirectUri in the ClientOptions must point to a page that calls loginCallback().

Copy
Copied
async login(
    options: Partial<LoginOptions> = {}
): Promise<void>

loginWithPopUp()

Initiates UAuth authentication with a React popup flow.

Copy
Copied
async loginWithPopup(
    options: Partial<Omit<LoginOptions, 'responseMode'>> = {},
    config?: PopupConfig,
): Promise<Authorization>

loginCallback()

Parses the authorization code and application state after login() has been called and the authorization server has redirected back to the redirectUri defined in the ClientOptions.

Copy
Copied
async loginCallback<T>(
    options?: Partial<LoginCallbackOptions>,
): Promise<LoginCallbackResponse<T>>

user()

Returns the UserInfo associated with the current UAuth instance.

Copy
Copied
async user(options: UserOptions = {}): Promise<UserInfo>

getVerifiedAccounts()

Retrieves all verified accounts associated with an authorized domain, with optional symbol filtering. Allows a dapp to request only the verified accounts they are interested in.

Copy
Copied
getVerifiedAccounts(
  authorization: Authorization, 
  symbols: string[] = []
): VerifiedAddress[]

getAuthorizationAccount

Retrieves the account that authorized a login request.

Copy
Copied
getAuthorizationAccount(
    authorization: Authorization, 
    type = 'sig', 
    version = 'v1'
): VerifiedAddress | undefined

logout()

Executes the beforeRedirect callback if defined in LogoutOptions, deletes the session authorization from the local clientstore, and redirects to the postLogoutRedirectUri.

Copy
Copied
async logout({
    clientID,
    username,
    scope,
    resource,
    ...options
}: Partial<LogoutOptions> = {}): Promise<void>

ClientOptions

The options object passed to the Client constructor.

Copy
Copied
export interface ClientOptions {
  // Fallback Login Options
  clientID: string
  clientSecret?: string
  redirectUri: string
  clientAuthMethod?: ClientAuthMethod
  resource?: string
  responseMode?: ResponseMode
  scope?: string
  prompt?: string
  maxAge?: number

  // Fallback Logout Options
  rpInitiatedLogout?: boolean
  postLogoutRedirectUri?: string

  // Cache Options
  cacheOptions?: CacheOptions

  // Other Options
  window?: Window | undefined
  fallbackIssuer?: string
  storeType?: StoreType
  store?: Store
  createIpfsUrl?: (cid: string, path: string) => string
  resolution?: DomainResolver
}

LoginOptions

The options object passed to login() and loginWithPopup().

Copy
Copied
interface LoginOptions {
  clientID: string
  clientSecret?: string
  clientAuthMethod: ClientAuthMethod
  maxAge: number
  prompt: string
  resource?: string
  redirectUri: string
  responseMode: ResponseMode
  scope: string
  flowId?: 'login' | 'signup'
  packageName?: string
  packageVersion?: string

  username?: string
  state?: any
  beforeRedirect?(url: string): Promise<void> | void
}

Authorization

The login authorization returned by loginWithPopup() and loginCallback().

Copy
Copied
interface Authorization {
  accessToken: string
  expiresAt: number
  idToken: IdToken
  scope: string
  resource?: string
}

AuthorizationOptions

Copy
Copied
interface AuthorizationOptions {
  clientID?: string
  username?: string
  scope?: string
  resource?: string
}

UserOptions

The options object passed to user().

Copy
Copied
interface UserOptions extends AuthorizationOptions {
  claims?: string[]
}

BaseLogoutOptions

Copy
Copied
interface BaseLogoutOptions {
  rpInitiatedLogout: boolean
  postLogoutRedirectUri?: string
}

LogoutOptions

The options object passed to logout(). Extends BaseLogoutOptions and AuthorizationOptions.

Copy
Copied
interface LogoutOptions {
  state?: any
  beforeRedirect?(url: string): Promise<void> | void
}

LoginCallbackOptions

The options object passed to loginCallback().

Copy
Copied
interface LoginCallbackOptions {
  url?: string
}

LoginCallbackResponse

The object returned by loginCallback().

Copy
Copied
interface LoginCallbackResponse<T> {
  authorization: Authorization
  state?: T
}

UserInfo

The object returned by user(). Equivalent to the response of the UserInfo endpoint of the UAuth server. Contains the claims requested by the current authorization session, based on the values defined in the ClientOptions.scope field. See Scopes for Login for more information about supported login scopes.

Copy
Copied
interface UserInfo {
// Partial<WalletClaims>
  wallet_address: string
  wallet_type_hint: WalletType
  eip4361_message: string
  eip4361_signature: string
            
// Partial<EmailClaims>
  email: string
  email_verified: boolean
            
// Partial<AddressClaims>
  address: AddressClaim

// Partial<PhoneClaims>
  phone_number: string
  phone_number_verified: boolean

// Partial<ProfileClaims>
  name: string
  given_name: string
  family_name: string
  middle_name: string
  nickname: string
  preferred_username: string
  profile: string
  picture: string
  website: string
  gender: string
  birthdate: string
  zoneinfo: string
  locale: string
  updated_at: string
            
// Partial<HumanityCheckClaims> { sub: string }
  humanity_check_id: string
}

VerifiedAddress

Defines a verified address associated with an authorized domain. Returned by getVerifiedAccounts() and getAuthorizationAccount().

Copy
Copied
interface VerifiedAddress {
  address: string
  message: string
  signature: string
  symbol: string
}