Login Configurations

Manage Login Configurations and User Groups with Affinidi Login Service.

Install Dependency

Package: @affinidi-tdk/login-configuration-client

npm install @affinidi-tdk/login-configuration-client --save

You can check the latest version of this module on the NPM repository or view the source code at the GitHub repository.

Classes and Methods

Configurations API

Use to manage Login Configuration to integrate Affinidi Login.

createLoginConfigurations

Create a new Login Configuration to integrate Affinidi Login.

Parameters

CreateLoginConfigurationInput [Object]

JSON object to provide the configuration details of the application. See more here.

Example

import { ConfigurationApi, Configuration, CreateLoginConfigurationInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

const request: CreateLoginConfigurationInput = {
    name: "Sample App",
    redirectUris: ["http://localhost:3000/auth/callback"]
}

const { data } = await api.createLoginConfigurations(request)

deleteLoginConfigurationsById

Delete an existing Login Configuration by ID.

Parameters

configurationId [String]

ID of the Login Configuration to delete.

Example

import { ConfigurationApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

// configurationID fetched from listLoginConfigurations
const configurationId = "<Config_ID>"

const result = await api.deleteLoginConfigurationsById(configurationId)

getClientMetadataByClientId

Retrieves the Client Metadata info of the Login Configuration by OAuth 2.0 Client ID.

Parameters

clientId [String]

OAuth 2.0 Client ID generated by Login Configuration.

Example

import { ConfigurationApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

// configurationID fetched from listLoginConfigurations
const configurationId = "<Config_ID>"

const { data } = await api.getClientMetadataByClientId(configurationId)

getLoginConfigurationsById

Retrieves the Login Configuration details by ID.

Parameters

configurationId [String]

ID of the existing Login Configuration to retrieve.

Example

import { ConfigurationApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

// configurationID fetched from listLoginConfigurations
const configurationId = "<Config_ID>"

const { data } = await api.getLoginConfigurationsById(configurationId)

listLoginConfigurations

List all the Login Configurations in the Project.

Parameters

limit [Integer]

Maximum number of records to fetch from the list.

exclusiveStartKey [String]

The base64url encoded key of the first item that this operation will evaluate (it is not returned). Use the value that was returned in the previous operation.

Example

import { ConfigurationApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

const { data } = await api.listLoginConfigurations()

updateLoginConfigurationsById

Update an existing Login Configuration by ID

Parameters

configurationId [String]

ID of the Login Configuration to update.

UpdateLoginConfigurationInput [Object]

JSON object to provide to update the Login Configuration details. See more here.

Example

import { ConfigurationApi, Configuration, UpdateLoginConfigurationInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new ConfigurationApi(authConfiguration)

// configurationID fetched from listLoginConfigurations
const configurationId = "<Config_ID>"

// create a request object of type UpdateLoginConfigurationInput and add the attributes to be changed
const request: UpdateLoginConfigurationInput = {
    name: "My Updated Login Config"
    redirectUris: ["http://localhost:3001/api/auth/callback"]
}

const { data } = await api.updateLoginConfigurationsById(configurationId, request)

Group API

Used to manage the User Groups for the Project.

addUserToGroup

Add user to the user group.

Parameters

groupName [String]

Name of the group to add the user.

AddUserToGroupInput [Object]

JSON object to provide with the ID of the user to add. See more here.

Example

import { GroupApi, Configuration, AddUserToGroupInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const groupName = "gold"

const userToBeAdded: AddUserToGroupInput = {
    userId: "did:key:890890890890890",
}

const { data } = await groupApi.addUserToGroup(groupName, userToBeAdded)

createGroup

Create a user group.

Parameters

CreateGroupInput [Object]

JSON object to provide the name of the user group.

Example

import { GroupApi, Configuration, CreateGroupInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const newGroupName : CreateGroupInput = {
    groupName: "silver"
}

const { data } = await groupApi.createGroup(newGroupName)

deleteGroup

Delete a group by name.

Parameters

groupName [String]

Name of the group to delete.

Example

import { GroupApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const groupName = "bronze"

const result = await groupApi.deleteGroup(groupName)

getGroupById

Retrieve a group by the group name.

Parameters

groupName [String]

Name of the group to retrieve.

Example

import { GroupApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const groupName = "silver"

const result = await groupApi.getGroupById(groupName)

listGroupUserMappings

List all the users from the group.

Parameters

groupName [String]

Name of the group to list.

limit [Integer]

Maximum number of records to fetch in a list.

exclusiveStartKey [String]

The base64url encoded key of the first item that this operation will evaluate (it is not returned). Use the value that was returned in the previous operation.

sortOrder [String]

sort response in specific order. By default it is in desc order.

Example

import { GroupApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const groupName = "gold"

const { data } = await groupApi.listGroupUserMappings(groupName)

listGroups

List all the groups in the Project.

Parameters

No Parameters Required

Example

import { GroupApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const { data } = await groupApi.listGroups()

removeUserFromGroup

Remove user from the group.

Parameters

groupName [String]

Name of the group where the user will be removed.

RemoveUserFromGroupInput [Object]

JSON object to provide the ID of the user to remove. See more here.

Example

import { GroupApi, Configuration, RemoveUserFromGroupInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const groupApi = new GroupApi(authConfiguration)

const groupName = "gold"

const userToRemove : RemoveUserFromGroupInput = {
    "userId": "did:key:890890890890890"
}

const { data } = await groupApi.removeUserFromGroup(groupName, userToRemove)

DenyList API

Used to block groups and users to deny access on services like Affinidi Login when users are authenticating.

blockGroups

Block users by group.

Parameters

GroupNamesInput [Object]

List of groups to block. See more here.

Example

import { DenyListApi, Configuration, GroupNamesInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const request: GroupNamesInput = [
    "group-1",
    "group-2"
]

const { data } = await api.blockGroups(request)

blockUsers

Block by User ID (DID).

Parameters

BlockedUsersInput [Object]

List of User IDs (DIDs) to block. See more here.

Example

import { DenyListApi, Configuration, BlockedUsersInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const request: BlockedUsersInput = [
    "user-1-did",
    "user-2-did"
]

const { data } = await api.blockUsers(request)

listBlockedGroups

Get list of blocked groups.

Parameters

pageToken [String]

Used for pagination.

Example

import { DenyListApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const { data } = await api.listBlockedGroups()

listBlockedUsers

Get list of blocked users.

Parameters

pageToken [String]

Used for pagination.

Example

import { DenyListApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const { data } = await api.listBlockedUsers()

unblockGroups

Unblock users by group.

Parameters

GroupNamesInput [Object]

List of groups to block. See more here.

Example

import { DenyListApi, Configuration, GroupNamesInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const request: GroupNamesInput = [
    "group-1-name",
    "group-2-name"
]

const { data } = await api.unblockGroups(request)

unblockUsers

Unblock by User ID (DID).

Parameters

BlockedUsersInput [Object]

List of User IDs (DIDs) to block. See more here.

Example

import { DenyListApi, Configuration, BlockedUsersInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new DenyListApi(authConfiguration)

const request: BlockedUsersInput = [
    "user-1-did",
    "user-2-did"
]

const { data } = await api.unblockUsers(request)

AllowList API

Used to allow groups and users to grant access on services like Affinidi Login when users are authenticating.

allowGroups

Allows users by group.

Parameters

GroupNamesInput [Object]

List of groups to allow. See more here.

Example

import { AllowListApi, Configuration, GroupNamesInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new AllowListApi(authConfiguration)

const request: GroupNamesInput = [
    "group-1",
    "group-2"
]

const { data } = await api.allowGroups(request)

disallowGroups

Disallow access to users by group.

Parameters

GroupNamesInput [Object]

List of groups to disallow. See more here.

Example

import { AllowListApi, Configuration, GroupNamesInput } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new AllowListApi(authConfiguration)

const request: GroupNamesInput = [
    "group-1",
    "group-2"
]

const { data } = await api.disallowGroups(request)

listAllowedGroups

Get list of allowed groups.

Parameters

pageToken [String]

Used for pagination.

Example

import { AllowListApi, Configuration } from '@affinidi-tdk/login-configuration-client'

// Pass the projectScopedToken generated from AuthProvider package
const authConfiguration = new Configuration({
  apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})

const api = new AllowListApi(authConfiguration)

const { data } = await api.listAllowedGroups()