Profile Claim
The Profile Claim is used to request personal information from a user's DID Wallet. This is a foundational step for many applications, enabling features like user registration, personalized experiences, and communication by securely obtaining user data with their explicit consent.
Structure#
The profile claim object is configured with the following parameters:
Parameter | Type | Description |
|---|---|---|
|
| Required. A message displayed to the user in their wallet, explaining why their profile information is being requested. E.g., "Please provide your profile to create an account." |
|
| An array specifying the profile fields to request. Defaults to |
|
| Optional. Any custom metadata you want to associate with the claim. This is not sent to the wallet but can be used in your application's logic. |
Available Profile Fields#
You can request any combination of the following fields in the items array:
Field | Description |
|---|---|
| The user's Decentralized Identifier. |
| The user's full name. |
| The user's email address. |
| The user's phone number. |
| A signature proving ownership of the DID. |
| A URL to the user's avatar image. |
| The user's date of birth. |
| A URL to the user's personal website or profile. |
Example: Requesting User Name and Email#
Here's how to configure DID Connect handlers to request the user's full name and email address. This is a common pattern for a simple login or registration flow.
DID Connect Handler
const { WalletHandlers } = require('@arcblock/did-connect');
const handlers = new WalletHandlers({
authenticator,
// ... other configurations
});
app.get('/api/auth/login', handlers.createAuthUrl({
claims: {
profile: {
description: 'Please provide your name and email to sign up.',
items: ['fullName', 'email'],
}
},
onAuth: async ({ userDid, userPk, claims }) => {
// The 'claims' array will contain the user's profile data
const profileData = claims.find(c => c.type === 'profile');
console.log('User DID:', userDid);
console.log('Profile Data:', profileData);
// TODO: Find or create a user in your database with the provided information
}
}));In this example:
- We define a
profileclaim within theclaimsobject. - The
descriptionprovides context to the user in their wallet. - The
itemsarray specifies that we need thefullNameandemail. - The
onAuthcallback receives the wallet's response, which includes aclaimsarray containing the requested profile information.
Wallet Response#
After the user approves the request in their DID Wallet, your onAuth callback will receive a payload containing the requested data. The claims array will hold an object of type profile with the user's information.
Wallet Response Example
{
"userDid": "z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ",
"userPk": "...",
"claims": [
{
"type": "profile",
"fullName": "Alice",
"email": "alice@example.com",
"meta": {}
}
],
"challenge": "...",
"status": "ok"
}Your application can then use this data to provision an account, personalize the user experience, or perform other actions as needed.
Next Steps#
After identifying the user with a profile claim, you might need to verify their control over the DID for security-sensitive operations. The Signature Claim is the perfect tool for this purpose.