Class: BaseUser
Types.BaseUser
Objects of this type represent an authenticated user. If you have a token you can instantiate your own User. This class is server side rendering (SSR) friendly as it only uses the fetch API with no other dependencies on browser APIs.
A User object gives you access to methods to:
- access or associate arbitrary private data to the user: please see the getBucket method; your backend will also be able to retrieve the data associated with your user by invoking the related SlashID User Management API https://developer.slashid.dev/docs/api/get-persons-person-id-attributes-bucket-name/;
- contextual user attributes as detailed in the Accessors section below;
Remarks
User objects are safe for serialization, you can pass them to other contexts with the postMessage
family of functions.
Hierarchy
BaseUser
↳
User
Constructors
constructor
• new BaseUser(token
, options?
)
Reconstruct an authenticated user from its token value.
Throws
TypeError
If the given optionsOrSid
, if defined, fail validation, or
the given token cannot be decoded.
Parameters
Name | Type | Description |
---|---|---|
token | string | A user token value. |
options? | SlashIDOptions | - |
Accessors
ID
• get
ID(): string
This user's ID. Use this property in your backend services when interacting with the SlashID User Management API.
Returns
string
anonymous
• get
anonymous(): boolean
Indicates if the user is an anonymous user
Returns
boolean
authentication
• get
authentication(): FactorMethod
[]
Indicates which authentication methods the user has been verified with. It can contain multiple items in case of multi factor authentication.
Returns
authentications
• get
authentications(): Authentication
[]
Indicates which authentication methods the user has been verified with, including the handles used for each method.
Returns
firstLogin
• get
firstLogin(): boolean
Indicates whether the user has been just registered, otherwise it's a returning user.
Returns
boolean
oid
• get
oid(): string
The organization ID this user belongs to.
Returns
string
token
• get
token(): string
The entire, signed authentication token of this user.
Returns
string
tokenClaims
• get
tokenClaims(): UserToken
The claims of the user token.
Returns
tokenContainer
• get
tokenContainer(): string
The entire token container
Returns
string
either the token container string or an empty string
tokenContainerClaims
• get
tokenContainerClaims(): undefined
| TokenContainer
If the user instance is created with a TokenContainer this will return the claims of the token container. Otherwise it will return undefined.
Returns
undefined
| TokenContainer
Methods
addGDPRConsent
▸ addGDPRConsent(request
): Promise
<GDPRConsentResponse
>
Add the GDPR consent levels to the current user. Consent levels not included in the request will not be changed.
Parameters
Name | Type | Description |
---|---|---|
request | GDPRConsentLevels | with consent levels to add |
Returns
GDPR consent info
createDirectID
▸ createDirectID(): Promise
<undefined
| string
>
Create a DirectID based on your token
Returns
Promise
<undefined
| string
>
directID token
delete
▸ delete(attributeNames
): Promise
<any
>
Deprecated
Use getBucket instead.
Parameters
Name | Type |
---|---|
attributeNames | string [] |
Returns
Promise
<any
>
get
▸ get<AttributesType
>(attributeNames?
): Promise
<AttributesType
>
Deprecated
Use getBucket instead.
Type parameters
Name | Type |
---|---|
AttributesType | extends JsonObject |
Parameters
Name | Type |
---|---|
attributeNames? | string [] |
Returns
Promise
<AttributesType
>
getAttributesClient
▸ getAttributesClient(): AttributesApi
Exposes the attributes client so the Bucket instance can access it
Returns
getBucket
▸ getBucket(bucketName?
): Bucket
Creates a Bucket object used to access attributes.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
bucketName | string | DefaultBucketName.end_user_read_write | name of the bucket we want to access - uses "end_user_read_write" as default. You can pass in any string that corresponds to a name of a bucket set up for your organization. You can use any of the preset bucket names with corresponding permissions and scopes - DefaultBucketName. |
Returns
getGDPRConsent
▸ getGDPRConsent(): Promise
<GDPRConsentResponse
>
Fetch the GDPR consent levels for the current user.
Returns
GDPR consent info
getGroups
▸ getGroups(): string
[]
Get an array of group names that the user belongs to.
Returns
string
[]
getHandles
▸ getHandles(): Promise
<PersonHandle
[]>
Fetch all the handles associated with this user from the SlashID API.
Returns
A list of handles available for the user
getOrganizations
▸ getOrganizations(): Promise
<OrganizationDetails
[]>
Get the organizations the user belongs to.
Returns
Promise
<OrganizationDetails
[]>
A list of organizations the user belongs to
getTokenForOrganization
▸ getTokenForOrganization(oid
): Promise
<string
>
Given an organization ID, get a new token for the same user in the Organization specified by the Organization ID.
For the call to succeed the following conditions must be met:
- the token must be valid at the time of the request
- the two Organizations must share the same person pool
- the user must be a member of both Organizations
This operation does not count as an authentication, so the new token will have the same expiration time as the original.
Parameters
Name | Type |
---|---|
oid | string |
Returns
Promise
<string
>
A new token for the specified Organization ID
isAuthenticated
▸ isAuthenticated(): Promise
<boolean
>
Indicates if the user is authenticated
For anonymous users this will return false
Returns
Promise
<boolean
>
logout
▸ logout(): Promise
<void
>
Log out of the current session. Clears the SlashID token. Will attempt revoking the token server-side.
Returns
Promise
<void
>
removeGDPRConsent
▸ removeGDPRConsent(request
): Promise
<void
>
Remove the GDPR consent levels from the current user. Consent levels not included in the request will not be changed.
Parameters
Name | Type | Description |
---|---|---|
request | DeleteConsentGdprRequest | with consentLevels to remove |
Returns
Promise
<void
>
removeGDPRConsentAll
▸ removeGDPRConsentAll(): Promise
<void
>
Remove all stored GDPR consent levels from the current user. Consent levels not included in the request will not be changed, unless deleteAll flag is set to true.
Returns
Promise
<void
>
set
▸ set<AttributesType
>(attributes
): Promise
<void
>
Deprecated
Use getBucket instead.
Type parameters
Name | Type |
---|---|
AttributesType | extends JsonObject |
Parameters
Name | Type |
---|---|
attributes | AttributesType |
Returns
Promise
<void
>
setGDPRConsent
▸ setGDPRConsent(request
): Promise
<GDPRConsentResponse
>
Set the GDPR consent levels for the current user. This will overwrite any existing consent levels and set the consent levels to only the ones included with the request.
Parameters
Name | Type | Description |
---|---|---|
request | GDPRConsentLevels | with consentLevels to set |
Returns
GDPR consent info
toJSON
▸ toJSON(): string
User objects encode to JSON as a string containing their token value.
Example
JSON.stringify(user) === "\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBTbWl0aCIsImlhdCI6MTUxNjIzOTAyMn0.dzKuKf6u9G7Crk9tsFnS2cey1zglWTFQv_hjWjmtXms\""
Returns
string
toString
▸ toString(): string
User objects stringify to their token value for convenience:
Example
user.toString() === "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBTbWl0aCIsImlhdCI6MTUxNjIzOTAyMn0.dzKuKf6u9G7Crk9tsFnS2cey1zglWTFQv_hjWjmtXms"
Returns
string
validateToken
▸ validateToken(): Promise
<ValidateTokenResponse
>
Resolves to a token validity info object which tells if the token is genuine and if it has expired yet.
Returns
Promise
<ValidateTokenResponse
>
Token validity info
createAnonymousUser
▸ Static
createAnonymousUser(options
): Promise
<BaseUser
>
Parameters
Name | Type |
---|---|
options | SlashIDOptions |