createoauthtoken

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package createoauthtoken exchanges an OAuth authorization code for a new connection: a token of kind oauth.

Index

Constants

View Source
const (
	// AccessLifetime is how long an access token works: the client refreshes it after.
	AccessLifetime = time.Hour
	// RefreshLifetime is how long a connection lasts without use: each refresh starts it again.
	RefreshLifetime = 90 * 24 * time.Hour
)

Variables

View Source
var ErrInvalidGrant = domain.Invalid("the code or refresh token is unknown, expired, already used, or of another client")

ErrInvalidGrant is the OAuth error invalid_grant: a code or refresh token unknown, expired, used, or of another client.

Functions

func Process

func Process(ctx context.Context, db bun.IDB, input Input) *run

Process exchanges an authorization code for a new connection: an access token of an hour and a refresh token of 90 days. The code serves once, used or refused.

func Verifies

func Verifies(verifier, challenge string) bool

Verifies tells if verifier is the one of challenge, PKCE S256: BASE64URL(SHA256(verifier)).

Types

type Input

type Input struct {
	Code         string
	ClientID     string
	ClientName   string // the name of the connection in the list of tokens
	RedirectURI  string
	CodeVerifier string
}

Input is the exchange of an authorization code (grant_type=authorization_code).

type Result

type Result struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

Result is the token answer of OAuth: the tokens go to the client, the base keeps their hash.

func NewTokens

func NewTokens() (Result, domain.Token)

NewTokens gives a new access token and refresh token, and the row fields they set: their hashes and expiries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL