A backend SDK for integrating with Universal Verify, an OAuth/OIDC platform that enables partners to access user information securely.
npm install universal-verify
import UniversalVerify from 'universal-verify';
// Initialize the SDK with your client credentials
const universalVerify = new UniversalVerify('your-client-id', 'your-client-secret');
new UniversalVerify(clientId, clientSecret)
Creates a new instance of the UniversalVerify SDK.
clientId
(string, required): Your Universal Verify client IDclientSecret
(string, required): Your Universal Verify client secret
Creates a PKCE code challenge from a code verifier.
codeVerifier
(string, optional): The code verifier. If not provided, a random one will be generated.
object
: An object containing:codeVerifier
(string): The code verifiercodeChallenge
(string): The generated code challenge
Exchanges an authorization code for access and refresh tokens.
options
(object):code
(string, required): The authorization code provided by the authorization servercodeVerifier
(string, required): The code verifier used to create the code challengeredirectUri
(string, required): The redirect URI used in the authorization request
Promise<object>
: The token response containing:access_token
(string): The access token (not provided if only the openid scope was requested)refresh_token
(string): The refresh token (not provided if only the openid scope was requested)id_token
(string): The OIDC ID token (only provided if the openid scope requested)expires_in
(number): The number of seconds until the access token expiresscope
(string): Space seperated list of scopes this access_token supportssub
(string): Unique user identifiertoken_type
(string): The type of token (always "Bearer")
Retrieves user information using an access token.
accessToken
(string, required): The access tokentimezone
(string, optional): The timezone to use when age is included in the response
Promise<object>
: The user information object containing:sub
(string): Unique user identifierverified
(boolean): Whether the user is verified (requires 'verification' scope)verification_confidence
(number): Confidence level of verification (1-3) (requires 'verification' scope)age
(number): User's age (requires 'age' scope)regional_info
(object): Regional information (requires one of: 'name', 'date_of_birth', or 'id_type' scopes)region
(string): User's regionadditional_userinfo_url
(string): URL for additional regional information
Retrieves user's regional information using an access token.
accessToken
(string, required): The access tokenregionalUrl
(string, required): The regional URL
Promise<object>
: The regional user information object containing:sub
(string): Unique user identifiername
(object): User's name informationfirst_name
(string): User's first namemiddle_names
(array): Array of user's middle nameslast_name
(string): User's last namesuffix
(string): The suffix portion of the user's namefull_name
(string): User's full name with an attempt at localization
date_of_birth
(string): User's date of birth in ISO 8601 format (YYYY-MM-DD)id_type
(object): Information about the ID used for verificationcountry
(string): Country that issued the IDtype
(string): Type of ID (e.g., 'state_id', 'passport')state
(string): State that issued the ID (if applicable)
Verifies a webhook signature. Throws an error if the signature is invalid.
payload
(string, required): The webhook payloadsignature
(string, required): The webhook signature
object
: The webhook's request body parameters containing:type
(string): The event type information (e.g. 'user.verification.updated')data
(object): The event-specific data (see webhook payload section for more details)
Error
: If the webhook signature is invalid
Revokes an access or refresh token.
token
(string, required): The token to revoke
Promise<object>
: The revocation result
Validates an ID token.
idToken
(string, required): The ID token to validatenonce
(string, optional): The nonce used if provided in the authorization request
Promise<object>
: The validated token claimsiss
(string): The issuer (https://api.universalverify.com)sub
(string): An ID for the user unique to the integrationaud
(string): Your integration's access keyexp
(number): The token's expiration time (unix time)iat
(number): The issued at time (unix time)verified
(boolean): Whether the user is verified (requires 'verification' scope)verification_confidence
(number): Verification confidence level (1-3) (requires 'verification' scope)
Refreshes an access token using a refresh token.
refreshToken
(string, required): The refresh token
Promise<object>
: The new token response containing:access_token
(string): The new access tokenrefresh_token
(string): The new refresh tokenexpires_in
(number): The number of seconds until the access token expiresscope
(string): Space seperated list of scopes this access_token supportssub
(string): Unique user identifiertoken_type
(string): The type of token (always "Bearer")
Returns the version of the UniversalVerify library.
console.log(UniversalVerify.version); // '0.0.1'
- Always use PKCE (Proof Key for Code Exchange) for secure OAuth flows
- Store client secrets securely and never expose them in client-side code
- Implement proper token validation and verification
- Use HTTPS for all communications
- Handle tokens securely and implement proper token refresh mechanisms
This webhook is triggered when a user's verification status or confidence level changes.
type
(string): The event type (always "user.verification.updated")data
(object): The event data containing:sub
(string): Unique user identifierverified
(boolean): New verification statusverification_confidence
(number | null): New verification confidence level (1-3)previous_values
(object): Previous verification valuesverified
(boolean): Previous verification statusverification_confidence
(number | null): Previous verification confidence level
MIT License - see LICENSE for details