IAM

Manage Projects and Access Policies with IAM Service.

Install Dependency

Package: affinidi_tdk_iam_client

pip install affinidi_tdk_iam_client

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

Classes and Methods

Projects API

Use the Projects API to manage your projects including providing access to other users on your projects.

add_principal_to_project

Add principal to the project to get access.

Parameters

addUserToProjectInput [Object]

JSON object to provide the principal ID and principal type to add to the project. See more here.

{
  "principalId": "<PRINCIPAL_ID>",
  "principalType": "<PRINCIPAL_TYPE>"
}
Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the projectScopedToken generated from AuthProvider package
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    request_json = {
      principalId: "PAT_ID",
      principalType: "token"
    }

    add_user_to_project_input = affinidi_tdk_iam_client.AddUserToProjectInput.from_dict(request_json)

    api_response = api_instance.add_principal_to_project(add_user_to_project_input=add_user_to_project_input)

create_project

Create a project for your account.

Parameters

CreateProjectInput [Object]

JSON object to provide the project name and description. See more here.

{
    "name": "<PROJECT_NAME>",
    "description": "<PROJECT_DESCRIPTION>"
}
Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    request_json = {
      name: "project_name",
      description: "project_description"
    }

    create_project_input = affinidi_tdk_iam_client.AddUserToProjectInput.from_dict(request_json)

    api_response = api_instance.create_project(create_project_input=create_project_input)

delete_principal_from_project

Delete principal (user or PAT) from the project to remove access.

Parameters

principalId [String]

ID of the User or Personal Access Token (PAT).

principalType [String]

Type of the Principal, user for User or token for Personal Access Token.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the projectScopedToken generated from AuthProvider package
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    principalId = "PAT_ID"
    principalType = "token"

    api_response = api_instance.delete_principal_from_project(principalId, principalType)

list_principals_of_project

Get the list of principals assigned to the project.

Parameters

No Parameters Required

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the projectScopedToken generated from AuthProvider package
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    api_response = api_instance.list_principals_of_project()

list_project

Get the list of projects.

Parameters

No Parameters Required

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    api_response = api_instance.list_project()

update_project

Update the project details.

Parameters

projectId [String]

ID of the project to update.

UpdateProjectInput [Object]

JSON object to provide the project name and description. See more here.

{
    "name": "<PROJECT_NAME",
    "description": "<PROJECT_DESCRIPTION>"
}
Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.ProjectsApi(api_client)

    projectId = "project_id"

    request_json = {
      name: "project_name",
      description: "project_description"
    }

    update_project_input = affinidi_tdk_iam_client.UpdateProjectInput.from_dict(request_json)

    api_response = api_instance.update_project(projectId, update_project_input=update_project_input)

Policies API

Use the Policies API to manage access to your projects and related resources for other users.

get_policies

Retrieves the policy attached to a principal.

Parameters

principalId [String]

ID of the User or Personal Access Token (PAT).

principalType [String]

Type of the Principal, user for User or token for Personal Access Token.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the projectScopedToken generated from AuthProvider package
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.PoliciesApi(api_client)

    principalId = "PAT_ID"
    principalType = "token"

    api_response = api_instance.get_policies(principalId, principalType)

update_policies

Update the Policy for the principal.

Parameters

principalId [String]

ID of the User or Personal Access Token (PAT).

principalType [String]

Type of the Principal, user for User or token for Personal Access Token.

policyDto [Object]

JSON object of Policy rules. See more here.

{
  "version": "2022-12-15",
  "statement": [
    {
      "principal": [
        "<PRINCIPAL_ID>"
      ],
      "action": [
        ""
      ],
      "resource": [
        ""
      ],
      "effect": "Allow"
    }
  ]
}
Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the projectScopedToken generated from AuthProvider package
configuration.api_key['ProjectTokenAuth'] = projectScopedToken

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.PoliciesApi(api_client)

    principalId = "PAT_ID"
    principalType = "token"

    policyInfo = {
      "version": "2022-12-15",
      "statement": [
        {
          "principal": [
            "<PRINCIPAL_ID>"
          ],
          "action": [
            ""
          ],
          "resource": [
            ""
          ],
          "effect": "Allow"
        }
      ]
    }

    api_response = api_instance.update_policies(principalId, principalType, 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.

create_project_scoped_token

Create a Project Scoped Token to access resources in the project.

Parameters

CreateProjectScopedTokenInput [Object]

JSON Object to provide the Project ID to generate the token. See more here.

{
    "projectId": "<PROJECT_ID>"
}
Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.StsApi(api_client)

    request_json = "{
      projectId: "project_id"
    }"

    create_project_scoped_token_input = affinidi_tdk_iam_client.CreateProjectScopedTokenInput.from_dict(request_json)

    api_response = api_instance.create_project_scoped_token(project_scoped_token_input=project_scoped_token_input)

whoami

Retrieve the principal information of the current user.

Paramaters

No Parameters Required

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.StsApi(api_client)

    api_response = api_instance.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.

create_token

Create a Personal Access Token.

Parameters

CreateTokenInput [Object]

JSON object to provide the details of the PAT like name and the public key info. See more here.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.TokensApi(api_client)

    jwks = "{
        keys: [
            {
            kid: "kid",
            alg: algorithm,
            use: "sig",
            kty: jwk.kty,
            n: jwk.n,
            e: jwk.e,
            },
        ],
    }"

    request_json = "{
        name: "token_name",
        authenticationMethod: {
            type: "PRIVATE_KEY",
            signingAlgorithm: algorithm,
            publicKeyInfo: {
                jwks,
            },
        },
    }"

    create_token_input = affinidi_tdk_iam_client.CreateTokenInput.from_dict(request_json)

    api_response = api_instance.create_token(create_token_input=create_token_input)

delete_token

Delete a Personal Access Token.

Parameters

tokenId [String]

ID of the Personal Access Token to delete.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.TokensApi(api_client)

    token_id = "token_id" 

    api_response =  api_instance.delete_token(token_id)

get_token

Retrieve the Personal Access Token details.

Parameters

tokenId [String]

ID of the Personal Access Token to retrieve.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.TokensApi(api_client)

    token_id = "token_id" 

    api_response = api_instance.get_token(token_id)

list_token

Get the list of Personal Access Token.

Parameters

No Parameters Required

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.TokensApi(api_client)

    api_response = api_instance.list_token()

update_token

Update an existing Personal Access Token.

Parameters

tokenId [String]

ID of the Personal Access Token to update.

UpdateTokenInput [Object]

JSON object to provide the details to update the Personal Access Token. See more here.

Example

import affinidi_tdk_iam_client

configuration = affinidi_tdk_iam_client.Configuration()
# Pass the User Token Auth generated from AuthProvider package
configuration.api_key['UserTokenAuth'] = "<USER_TOKEN_AUTH>"

with affinidi_tdk_iam_client.ApiClient(configuration) as api_client:
    api_instance = affinidi_tdk_iam_client.TokensApi(api_client)

    token_id = "token_id"
    jwks = "{
        keys: [
            {
            kid: "kid",
            alg: algorithm,
            use: "sig",
            kty: jwk.kty,
            n: jwk.n,
            e: jwk.e,
            },
        ],
    }"

    request_json = "{
        name: "token_name",
        authenticationMethod: {
            type: "PRIVATE_KEY",
            signingAlgorithm: algorithm,
            publicKeyInfo: {
                jwks,
            },
        },
    }"

    update_token_input = affinidi_tdk_iam_client.UpdateTokenInput.from_dict(request_json)

    api_response = api_instance.update_token(token_id, update_token_input=update_token_input)