Managing API tokens
API tokens can be used as an authentication mechanism for Infrahub's REST- and GraphQL API, the Python SDK and infrahubctl.
- Via the Web Interface
- Via the GraphQL Interface
- Login to Infrahub's web interface as an administrator.
- Click on the user in the left side menu.
- Navigate to the Account settings.
- In the user profile page, click on Tokens tab.
- Click + Add Account Token.
- Fill in the details and click Save.
- Copy the generated token and store in a safe location.
- Deleting a token can be achieved by selecting the trash icon on the token table item.
Creating a new API Token
In the GraphQL sandbox, execute the following mutation, replace the name of the token in the mutation with a value that is appropriate for your use case:
mutation {
InfrahubAccountTokenCreate(data: {name: "token name"}) {
object {
token {
value
}
}
}
}
The result of the query will show you the value of the token that was generated for the token. Store the token in a secure location, as there will be no way to retrieve the token from Infrahub at a later stage.
Listing existing API Tokens for a user
In the GraphQL sandbox, execute the following query:
query {
InfrahubAccountToken {
edges {
node {
name
expiration
id
}
}
}
}
Deleting an API token for a user
In the GraphQL sandbox, execute the following mutation, replace the id of the token in the mutation with the id of the token that you want to delete:
mutation {
InfrahubAccountTokenDelete(data: {id: "17d8cde3-d36b-a0a3-370e-c51707234f19"}) {
ok
}
}