Export and Import Affinidi Login Setup

In this guide, learn how to export and import your Login Configurations and User Groups.

Affinidi CLI and Affinidi Portal allows you to export your Login Configurations and User Groups created under a particular project. Using the exported JSON file, you can import them to your selected project. To do this, follow the steps below:

Before you begin
  1. Set up Affinidi Vault account. Follow the guide below if you haven’t set it up yet.
Set up Affinidi Vault

Set up an Affinidi Vault account using the Web Vault or install the Mobile Vault (for Android).

The same setup steps for Mobile Vault.

  1. Click on Get started if you are creating a new account, or click on Restore from Backup if you have an existing backup of your Affinidi Vault. Provide the Passphrase to secure your Affinidi Vault.

You have the option to enable Biometrics to unlock your Affinidi Vault easily instead of using Passphrase.

Affinidi Vault Setup
  1. Enter your email address to register with the Affinidi Vault. An OTP will be sent to this email for verification.
Affinidi Vault Passphrase
  1. Enter the OTP sent to the email you have provided for verification to complete the setup.
Affinidi Vault Email Verification

After successfully providing the OTP, you are redirected to the Affinidi Vault dashboard.

  1. Install the Affinidi CLI. Follow the guide below if it hasn’t been installed.
Set up Affinidi CLI
  1. Download and install NodeJS on your machine if you haven’t set it up yet.
  1. Install Affinidi CLI using Node Package Manager (npm).
npm install -g @affinidi/cli
  1. Verify that the installation is successful.
affinidi --version

Export and Import Using Affinidi Portal

Export and Import Login Configurations and Groups using Portal

Export Login Configurations and User Groups

  1. Go to  Affinidi Portal and log in to the Affinidi Portal using your Affinidi Vault.

  2. Go to Affinidi Login service and click on dropdown button called Actions. Make sure that you have selected the project where you want to export the Login Configurations and User Groups.

  3. Click on Export login configurations to export your Login Configuration created under the current project. Additionally, you can export also the User Groups by clicking on the Export groups button.

Import Login Configurations and User Groups

  1. Go to  Affinidi Portal and log in to the Affinidi Portal using your Affinidi Vault.

  2. Go to Affinidi Login service and click on dropdown button called Actions. Make sure that you have selected the project where you want to import the Login Configurations and User Groups.

  3. Click on Import login configurations to import your Login Configuration created under the current project. Click on Import groups if you want to import the User Groups to the same project.

Export and Import Using Affinidi CLI

Export and Import functionality is also available using Affinidi CLI. Follow the steps below on how to do this.

Export Login Configurations and User Groups

  1. You must log in to the Project where you want to export your Login Configurations.
affinidi start

or if you are already logged in and want to switch to another project, use the following command:

affinidi project select-project --project-id <PROJECT_ID>

Export Login Configurations

  1. Once you log in to the Project, run the following command to export Login Configuration.
affinidi login export-configs --path ~/Downloads/login_configs_backup.json

It will prompt you which Login Configurations you want to export. You can select each Login Configuration using <space> or click <a> to select all. Optionally, you can set the parameter -i, --ids to list all the Login Configurations IDs to export separated by <space>.

  1. Once you have selected the Login Configurations to export, it will generate the export file based on the path provided in the command with the list of Login Configurations.
{
  "data": {
    "configurations": [
      {
        "name": "NextJS Basic",
        "redirectUris": [
          "http://localhost:3000/api/auth/callback/affinidi"
        ],
        "presentationDefinition": {
          ...
        },
        "idTokenMapping": [
          ...
        ],
        "clientMetadata": {
          ,,,
        },
        "tokenEndpointAuthMethod": "client_secret_post"
      }
    ]
  }
}

Export User Groups

  1. To export the User Groups from the current Project, run the following command.
affinidi login export-groups --path ~/Downloads/user_groups_backup.json

It will prompt you which User Groups you want to export. You can select each User Group using <space> or click <a> to select all. Optionally, you can set the parameter -i, --ids to list all the User Groups IDs to export separated by <space>.

  1. Once you have selected the User Groups to export, it will generate the export file based on the path provided in the command with the list of User Groups.
{
  "data": {
    "groups": [
      {
        "groupName": "all_users",
        "users": [
          "did:key...
        ]
      }
    ]
  }
}

Import Login Configurations and User Groups

To import Login Configuration from a backup file, follow the steps below:

  1. You must log in to the Project where you want to export your Login Configurations.
affinidi start

or if you are already logged in and want to switch to another project, use the following command:

affinidi project select-project --project-id <PROJECT_ID>

Import Login Configurations

  1. Once you log in to the Project, run the following command to import Login Configuration.
affinidi login import-configs --path ~/Downloads/login_configs_backup.json
  1. Once you import the Login Configurations from your backup file, it will regenerate all the Login Configurations, including client credentials and list them on the screen.
Importing login configurations... Imported successfully!
 ›   Warning: Please save the clientSecret somewhere safe. You will not be able to view it again.
{
  "configurations": [
    {
      "ari": "ari:identity:ap-southeast-1:khyg8765-a0b7-89t7-881e-95cd8688a78f:login_configuration/p098u7yg-0i8j-44b5-8b69-ff4273adc8bc",
      "projectId": "khyg8765-a0b7-89t7-881e-95cd8688a78f",
      "configurationId": "p098u7yg-0i8j-44b5-8b69-ff4273adc8bc",
      "name": "NextJS Basic",
      "auth": {
        "clientId": "<CLIENT_ID>",
        "clientSecret": "<CLIENT_SECRET",
        "issuer": "<ISSUER>"
      },
      "redirectUris": [
        "http://localhost:3000/api/auth/callback/affinidi"
      ],
      "clientMetadata": {
        "name": "NextJS Basic",
        "origin": "http://localhost:3000",
        "logo": "https://login.affinidi.com/default-client-logo.svg"
      },
      "creationDate": "2023-11-21T02:11:41Z",
      "tokenEndpointAuthMethod": "client_secret_post"
    }
  ]
}

Import User Groups

  1. To import the User Groups from the backup file to the current Project.
affinidi login import-configs --path ~/Downloads/login_configs_backup.json
  1. Once you have imported the User Groups, it will create the user groups, including the DIDs of the users.
Importing groups... Imported successfully!
{
  "groups": [
    {
      "ari": "ari:identity:ap-southeast-1:khyg8765-a0b7-89t7-881e-95cd8688a78f:group/user_sample",
      "groupName": "user_sample",
      "projectId": "khyg8765-a0b7-89t7-881e-95cd8688a78f",
      "creationDate": "2023-11-21T02:21:19.731Z"
    }
  ]
}