IAM
Install Dependency
Package: @affinidi-tdk/iam-client
npm install @affinidi-tdk/iam-client --saveCheck the latest version on the npm registry or view the source on GitHub.
Classes and Methods
Projects API
Use the Projects API to manage your projects including providing access to other users on your projects.
addPrincipalToProject
Adds a principal to the project.
Parameters
principalType is "user" for a user account or "token" for a Personal Access Token.Example
import { ProjectsApi, Configuration, AddUserToProjectInput } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)
const request: AddUserToProjectInput = {
principalId: '<PAT_ID>',
principalType: 'token',
}
const { data } = await api.addPrincipalToProject(request)createProject
Creates a project for your account.
Parameters
Example
import { ProjectsApi, Configuration, CreateProjectInput } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const request: CreateProjectInput = {
name: 'project_name',
description: 'project_description',
}
const { data } = await api.createProject(request)deletePrincipalFromProject
Removes a principal (user or PAT) from the project.
Parameters
principalId
string
RequiredprincipalType
string
Required"user" for a user account or "token" for a Personal Access Token.Example
import { ProjectsApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)
await api.deletePrincipalFromProject('<PAT_ID>', 'token')listPrincipalsOfProject
Returns the list of principals assigned to the project.
No parameters required.
Example
import { ProjectsApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)
const { data } = await api.listPrincipalsOfProject()listProject
Returns the list of projects.
No parameters required.
Example
import { ProjectsApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const { data } = await api.listProject()updateProject
Updates the project details.
Parameters
projectId
string
RequiredExample
import { ProjectsApi, Configuration, UpdateProjectInput } from '@affinidi-tdk/iam-client'
const api = new ProjectsApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const request: UpdateProjectInput = {
name: 'project_name',
description: 'project_description',
}
const { data } = await api.updateProject('<PROJECT_ID>', request)Policies API
Use the Policies API to manage access to your projects and related resources for other users.
getPolicies
Retrieves the policy attached to a principal.
Parameters
principalId
string
RequiredprincipalType
string
Required"user" for a user account or "token" for a Personal Access Token.Example
import { PoliciesApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new PoliciesApi(
new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)
const { data } = await api.getPolicies('<PAT_ID>', 'token')updatePolicies
Updates the policy for a principal.
Parameters
principalId
string
RequiredprincipalType
string
Required"user" for a user account or "token" for a Personal Access Token.Example
import { PoliciesApi, Configuration, PolicyDto } from '@affinidi-tdk/iam-client'
const api = new PoliciesApi(
new Configuration({ apiKey: authProvider.fetchProjectScopedToken.bind(authProvider) })
)
const policyInfo: PolicyDto = {
version: '2022-12-15',
statement: [
{
principal: ['<PRINCIPAL_ID>'],
action: [''],
resource: [''],
effect: 'Allow',
},
],
}
await api.updatePolicies('<PAT_ID>', 'token', policyInfo)Secure Token Exchange (STS) API
Use the STS (Secure Token Exchange) API to create a Project Scoped Token and get the current session information.
createProjectScopedToken
Creates a Project Scoped Token to access resources in the project.
Parameters
Example
import { StsApi, Configuration, CreateProjectScopedTokenInput } from '@affinidi-tdk/iam-client'
const api = new StsApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const request: CreateProjectScopedTokenInput = {
projectId: '<PROJECT_ID>',
}
const { data } = await api.createProjectScopedToken(request)whoami
Retrieves the principal information of the current session.
No parameters required.
Example
import { StsApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new StsApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const { data } = await api.whoami()Tokens API
Use the Tokens API to create a Personal Access Token (PAT) to call Affinidi services on your behalf. Alternatively, use the Token command from Affinidi CLI.
createToken
Creates a Personal Access Token.
Parameters
Example
import { TokensApi, Configuration, CreateTokenInput } from '@affinidi-tdk/iam-client'
const api = new TokensApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const jwks = {
keys: [
{
kid: 'kid',
alg: algorithm,
use: 'sig',
kty: jwk.kty,
n: jwk.n,
e: jwk.e,
},
],
}
const request: CreateTokenInput = {
name: 'token_name',
authenticationMethod: {
type: 'PRIVATE_KEY',
signingAlgorithm: algorithm,
publicKeyInfo: { jwks },
},
}
const { data } = await api.createToken(request)deleteToken
Deletes a Personal Access Token.
Parameters
tokenId
string
RequiredExample
import { TokensApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new TokensApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
await api.deleteToken('<TOKEN_ID>')getToken
Retrieves the details of a Personal Access Token.
Parameters
tokenId
string
RequiredExample
import { TokensApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new TokensApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const { data } = await api.getToken('<TOKEN_ID>')listToken
Returns the list of Personal Access Tokens.
No parameters required.
Example
import { TokensApi, Configuration } from '@affinidi-tdk/iam-client'
const api = new TokensApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const { data } = await api.listToken()updateToken
Updates an existing Personal Access Token.
Parameters
tokenId
string
RequiredExample
import { TokensApi, Configuration, UpdateTokenInput } from '@affinidi-tdk/iam-client'
const api = new TokensApi(
new Configuration({ apiKey: '<USER_TOKEN_AUTH>' })
)
const jwks = {
keys: [
{
kid: 'kid',
alg: algorithm,
use: 'sig',
kty: jwk.kty,
n: jwk.n,
e: jwk.e,
},
],
}
const request: UpdateTokenInput = {
name: 'token_name',
authenticationMethod: {
type: 'PRIVATE_KEY',
signingAlgorithm: algorithm,
publicKeyInfo: { jwks },
},
}
const { data } = await api.updateToken('<TOKEN_ID>', request)Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.