Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.domain.tokens

Create, acquire, and manage personal access tokens.

Submodules

Package Contents

CreateCredentialRequest

class roboto.domain.tokens.CreateCredentialRequest(/, **data)#View Source

Bases: pydantic.BaseModel

Request payload to create a credential request.

The CLI redeems the request for a personal access token after a user approves it in the browser.

Parameters

data Any

Attributes

CreateCredentialRequest.client_hostname

client_hostname str #

Hostname shown on the approval page: 1-255 printable ASCII characters, declared by the client.

CreateCredentialRequest.client_version

client_version str #

CLI version shown on the approval page: 1-64 printable ASCII characters, declared by the client.

CreateCredentialRequest.code_challenge

code_challenge str #

Unpadded base64url encoding of the SHA-256 digest of the CLI’s secret code verifier.

CreateCredentialRequest.code_challenge_method

code_challenge_method Literal['S256'] = 'S256' #

Challenge method. Only S256 is supported.

CreateCredentialRequest.redirect_uri

redirect_uri str | None = None #

Loopback URL (http://127.0.0.1:<port>/callback or http://[::1]:<port>/callback) the browser is sent to after approval. The port must be 1-65535; credentials, query strings, and fragments are refused.

When omitted, the web app shows the authorization code for the user to paste into the CLI instead, which is how login works on a machine without a browser.

CreateCredentialRequest.state

state str | None = None #

Random value of 16 to 256 URL-safe characters, echoed back on the loopback redirect so the CLI can reject callbacks it did not ask for. Required with redirect_uri and rejected without it.

CreateCredentialRequest.token_expiry_days

token_expiry_days int #

Number of days, from 1 to MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS, that the personal access token stays valid.

The lifetime starts when the CLI redeems the approved request.

CreateCredentialRequestResult

class roboto.domain.tokens.CreateCredentialRequestResult(/, **data)#View Source

Bases: pydantic.BaseModel

Creation result for a credential request that expires ten minutes after creation.

Parameters

data Any

Attributes

CreateCredentialRequestResult.approval_url

approval_url str #

Web app URL where the user reviews and approves the request.

CreateCredentialRequestResult.confirmation_code

confirmation_code str #

Short code the CLI prints and the approval page shows, so the user can check they are the same request.

CreateCredentialRequestResult.credential_request_id

credential_request_id str #

Unique identifier for the request. Redeeming it also requires its authorization code and secret verifier.

CreateCredentialRequestResult.expires

expires datetime.datetime #

Time after which the request can no longer be approved or redeemed.

CreateTokenRequest

class roboto.domain.tokens.CreateTokenRequest(/, **data)#View Source

Bases: pydantic.BaseModel

Request payload to create a new token

Parameters

data Any

Attributes

CreateTokenRequest.api_scopes

api_scopes set[roboto.auth.scope.ApiScope] | None = None #

CreateTokenRequest.description

description str | None = None #

CreateTokenRequest.expiry_days

expiry_days int = None #

CreateTokenRequest.name

name str = None #

ExchangeCredentialRequestCode

class roboto.domain.tokens.ExchangeCredentialRequestCode(/, **data)#View Source

Bases: pydantic.BaseModel

Redeem an approved request’s authorization code for a personal access token.

Credential values are serialized for exchange, but hidden from model representations and rendered validation errors. Structured validation errors include input by default; use errors(include_input=False) when logging them.

Parameters

data Any

Attributes

ExchangeCredentialRequestCode.authorization_code

authorization_code str = None #

One-time authorization code delivered to the CLI by the loopback redirect or pasted by the user.

ExchangeCredentialRequestCode.code_verifier

code_verifier str = None #

Secret verifier whose SHA-256 digest, encoded as unpadded base64url, was sent as code_challenge.

ExchangeCredentialRequestCode.credential_request_id

credential_request_id str #

ID of the request the code was issued for.

ExchangeCredentialRequestCode.model_config

model_config #

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS

roboto.domain.tokens.MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS = 365#View Source

Longest token lifetime, in days, that a CreateCredentialRequest may ask for.

It matches the longest lifetime the Roboto web app offers for a new access token.

Token

class roboto.domain.tokens.Token(record, roboto_client=None)#View Source

A token allows users and devices to authenticate requests to Roboto.

When a token is generated, a secret value is created which is shared with the user exactly once. This value is required for authentication, if lost a token can be deleted and a new token can be generated.

Token.create()

classmethod create(name, description=None, expiry_days=30, api_scopes=None, roboto_client=None)#View Source

This returns a tuple of the token and the one-time generated secret. After creation, you’ll never be able to retrieve the secret again, so you should save it!

Parameters

name str
description Optional[str]
expiry_days int
api_scopes Optional[set[roboto.auth.scope.ApiScope]]
roboto_client Optional[roboto.http.RobotoClient]

Return type

tuple[Token, str]

Token.delete()

delete()#View Source

Return type

None

Token.disable()

disable()#View Source

Return type

Token.enable()

enable()#View Source

Return type

Token.for_self()

classmethod for_self(roboto_client=None)#View Source

Parameters

roboto_client Optional[roboto.http.RobotoClient]

Return type

collections.abc.Collection[Token]

Token.from_id()

classmethod from_id(token_id, roboto_client=None)#View Source

Parameters

token_id str
roboto_client Optional[roboto.http.RobotoClient]

Return type

Token.to_dict()

to_dict()#View Source

Return type

dict[str, Any]

Properties

Token.token_id

token_id str #
Return type: str

Token.user_id

user_id str #
Return type: str

TokenContext

class roboto.domain.tokens.TokenContext(/, **data)#View Source

Bases: pydantic.BaseModel

Context for token usage

Parameters

data Any

Attributes

TokenContext.api_scopes

TokenContext.description

description str | None = None #

TokenContext.enabled

enabled bool = True #

TokenContext.expires

expires datetime.datetime #

TokenContext.last_used

last_used datetime.datetime | None = None #

TokenContext.name

name str #

TokenContext.token_id

token_id str #

TokenRecord

class roboto.domain.tokens.TokenRecord(/, **data)#View Source

Bases: pydantic.BaseModel

A wire-transmissible representation of a token.

Parameters

data Any

Attributes

TokenRecord.context

context TokenContext | None = None #

TokenRecord.secret

secret str | None = None #

TokenRecord.user_id

user_id str | None = None #

Was this page helpful?