Class: AnonymousUser
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
↳
AnonymousUser
Constructors
constructor
• new AnonymousUser(token, slashid)
Reconstruct an anonymous user from its token value. Call the id method to authenticate the user.
If this results with registering a new user, the underlying user ID will be the same as the originating anonymous user.
Instances can only be constructed in a browser environment due to dependency on SlashID.
Throws
TypeError the given token cannot be decoded.
Parameters
| Name | Type | Description |
|---|---|---|
token | string | A user token value. |
slashid | SlashID | SlashID instance |
Overrides
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
Inherited from
BaseUser.ID
anonymous
• get anonymous(): boolean
Indicates if the user is an anonymous user
Returns
boolean
Inherited from
BaseUser.anonymous
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
Inherited from
BaseUser.authentication
authentications
• get authentications(): Authentication[]
Indicates which authentication methods the user has been verified with, including the handles used for each method.
Returns
Inherited from
BaseUser.authentications
firstLogin
• get firstLogin(): boolean
Indicates whether the user has been just registered, otherwise it's a returning user.
Returns
boolean
Inherited from
BaseUser.firstLogin
oid
• get oid(): string
The organization ID this user belongs to.
Returns
string
Inherited from
BaseUser.oid
token
• get token(): string
The entire, signed authentication token of this user.
Returns
string
Inherited from
BaseUser.token
tokenClaims
• get tokenClaims(): UserToken
The claims of the user token.
Returns
Inherited from
BaseUser.tokenClaims
tokenContainer
• get tokenContainer(): string
The entire token container
Returns
string
either the token container string or an empty string
Inherited from
BaseUser.tokenContainer
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
Inherited from
BaseUser.tokenContainerClaims
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
Inherited from
createDirectID
▸ createDirectID(): Promise<undefined | string>
Create a DirectID based on your token
Returns
Promise<undefined | string>
directID token
Inherited from
delete
▸ delete(attributeNames): Promise<any>
Deprecated
Use getBucket instead.
Parameters
| Name | Type |
|---|---|
attributeNames | string[] |
Returns
Promise<any>
Inherited from
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>
Inherited from
getAttributesClient
▸ getAttributesClient(): AttributesApi
Exposes the attributes client so the Bucket instance can access it
Returns
Inherited from
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
Inherited from
getGDPRConsent
▸ getGDPRConsent(): Promise<GDPRConsentResponse>
Fetch the GDPR consent levels for the current user.
Returns
GDPR consent info
Inherited from
getGroups
▸ getGroups(): string[]
Get an array of group names that the user belongs to.
Returns
string[]
Inherited from
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
Inherited from
getOrganizations
▸ getOrganizations(): Promise<OrganizationDetails[]>
Get the organizations the user belongs to.
Returns
Promise<OrganizationDetails[]>
A list of organizations the user belongs to
Inherited from
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
Inherited from
BaseUser.getTokenForOrganization
id
▸ id(handle, authenticationFactor): Promise<User>
Authenticates the [AnonymousUser], on success the user is now a permanently registered user.
Parameters
| Name | Type |
|---|---|
handle | PersonHandle |
authenticationFactor | Factor |
Returns
Promise<BrowserUser>
isAuthenticated
▸ isAuthenticated(): Promise<boolean>
Indicates if the user is authenticated
For anonymous users this will return false
Returns
Promise<boolean>
Inherited from
logout
▸ logout(): Promise<void>
Log out of the current session. Clears the SlashID token. Will attempt revoking the token server-side.
Returns
Promise<void>
Inherited from
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>
Inherited from
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>
Inherited from
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>
Inherited from
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
Inherited from
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
Inherited from
toString
▸ toString(): string
User objects stringify to their token value for convenience:
Example
user.toString() === "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBTbWl0aCIsImlhdCI6MTUxNjIzOTAyMn0.dzKuKf6u9G7Crk9tsFnS2cey1zglWTFQv_hjWjmtXms"
Returns
string
Inherited from
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
Inherited from
createAnonymousUser
▸ Static createAnonymousUser(options): Promise<BaseUser>
Parameters
| Name | Type |
|---|---|
options | SlashIDOptions |