open_payments/grants

Types

Wraps the access requested for the token issued by a grant.

pub type AccessTokenBodyProperty {
  AccessTokenBodyProperty(access: List(types.Access))
}

Constructors

The request body sent to the auth server to request a grant.

pub type Body {
  Body(
    access_token: AccessTokenBodyProperty,
    client: ClientType,
    interact: option.Option(Interact),
  )
}

Constructors

How the client making the grant request identifies itself: either directly with its public key (jwk), or via a wallet address whose keys the auth server can look up.

pub type ClientType {
  ClientDirectedIdentity(jwk: types.Key)
  ClientWalletAddressObject(wallet_address: String)
}

Constructors

  • ClientDirectedIdentity(jwk: types.Key)
  • ClientWalletAddressObject(wallet_address: String)

The result of continuing a pending grant. access_token is present once the grant has been approved.

pub type ContinuationResponse {
  ContinuationResponse(
    access_token: option.Option(types.AccessTokenResponse),
    continue: ContinueResponse,
  )
}

Constructors

The access token used to continue a pending grant.

pub type ContinueAccessToken {
  ContinueAccessToken(value: String)
}

Constructors

  • ContinueAccessToken(value: String)

Where and how to continue a grant, and how long to wait before polling again.

pub type ContinueResponse {
  ContinueResponse(
    access_token: ContinueAccessToken,
    uri: String,
    wait: option.Option(Int),
  )
}

Constructors

How the client is notified once the user has completed interaction with the auth server, as requested in a grant’s interact options.

pub type Finish {
  Finish(method: String, uri: String, nonce: String)
}

Constructors

  • Finish(method: String, uri: String, nonce: String)

The options for a grant request. access may list more than one access kind (e.g. incoming-payment and quote) to request them all in a single grant. client_type defaults to identifying the client by its own wallet address (ClientWalletAddressObject) when left as None; pass Some(ClientDirectedIdentity(key)) to identify the client by its public key instead. See https://openpayments.dev/apis/auth-server/operations/post-request/

pub type GrantOptions {
  GrantOptions(
    auth_server_url: String,
    access: List(types.Access),
    interact: option.Option(Interact),
    address: String,
    client_type: option.Option(ClientType),
  )
}

Constructors

The result of a grant request. A grant is either pending client interaction (PendingGrant) or has already been approved (Grant). See https://openpayments.dev/apis/auth-server/operations/post-request/

pub type GrantResponse {
  PendingGrant(
    interact: InteractResponse,
    continue: ContinueResponse,
  )
  Grant(
    access_token: types.AccessTokenResponse,
    continue: ContinueResponse,
  )
}

Constructors

The interaction methods to request for a grant, and optionally how the client should be notified when interaction finishes.

pub type Interact {
  Interact(start: List(String), finish: option.Option(Finish))
}

Constructors

Where to redirect the user to interact with the auth server, and how the client will be notified once interaction finishes.

pub type InteractResponse {
  InteractResponse(
    redirect: String,
    finish: option.Option(String),
  )
}

Constructors

  • InteractResponse(redirect: String, finish: option.Option(String))

Values

pub fn cancel(
  client: client.Client,
  response: ContinueResponse,
) -> Result(Nil, error.OpenPaymentsError)

Cancels a pending grant request, invalidating its continuation so it can no longer be used to continue or retrieve the grant. See https://openpayments.dev/apis/auth-server/operations/delete-continue/

pub fn continue(
  client: client.Client,
  response: ContinueResponse,
  interact_ref: String,
) -> Result(ContinuationResponse, error.OpenPaymentsError)

Continues a pending grant after the user has completed interaction. See https://openpayments.dev/apis/auth-server/operations/post-continue/

pub fn is_interactive_grant(grant: GrantResponse) -> Bool

Returns True if the grant requires the user to complete an interaction before it can be used.

pub fn request(
  client: client.Client,
  options: GrantOptions,
) -> Result(GrantResponse, error.OpenPaymentsError)

Requests a grant from the auth server for the given access. Pass more than one Access in options.access to request them all under a single grant, rather than requesting each with its own grant. See https://openpayments.dev/apis/auth-server/operations/post-request/

Search Document