Skip to main content

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:

ParameterTypeDescription
descriptionstringRequired. 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."
itemsstring[]An array specifying the profile fields to request. Defaults to ['fullName']. See the "Available Profile Fields" table below for all options. The key fields can also be used as an alias for items.
metaanyOptional. 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:

FieldDescription
didThe user's Decentralized Identifier.
fullNameThe user's full name.
emailThe user's email address.
phoneThe user's phone number.
signatureA signature proving ownership of the DID.
avatarA URL to the user's avatar image.
birthdayThe user's date of birth.
urlA 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

javascript
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:

  1. We define a profile claim within the claims object.
  2. The description provides context to the user in their wallet.
  3. The items array specifies that we need the fullName and email.
  4. The onAuth callback receives the wallet's response, which includes a claims array 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

json
{
  "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.