grant

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 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 grant is the source of the access tokens of a sign-in, which is stored as a credential, such as by POST /credential/{key}/signin: the token is refreshed, with the secret of the client, which is another credential, and stored again, once it has expired.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Server   authclient.ServerMetadata // The authorization server, such as Google
	Client   string                    // The key of the credential of its OAuth client, such as GOOGLE_CLIENT
	Key      string                    // The key of the credential of the sign-in, such as GOOGLE_TOKEN
	Required []string                  // The sign-in has one of these scopes
	Scopes   []string                  // The scopes which are asked for, when signing in
}

Config is the sign-in which a source's tokens are of

type Credentials

type Credentials interface {
	// Get returns the credential for the key, as JSON
	Get(ctx context.Context, key string) (json.RawMessage, error)

	// Set stores the credential for the key, which is JSON
	Set(ctx context.Context, key string, value json.RawMessage) error
}

Credentials are what a source reads its client, and sign-in, from, and stores the sign-in to, which a credential.CredentialProvider is

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is the source of the access tokens of a sign-in, which is safe to use from more than one goroutine

func New

func New(ctx context.Context, credentials Credentials, config Config) (*Source, error)

New returns the source of the access tokens of the sign-in, which must be the server's, for the client, and have one of the required scopes. Returns a SignInError, with how to sign in, which wraps ErrInvalidProvider, when the person hasn't, or their sign-in is for another client, or doesn't have the scopes. Returns ErrServiceUnavailable when there are no credentials, or no client, as no one can sign in, and ErrBadParameter when the client isn't one.

func (*Source) SignIn

func (self *Source) SignIn(err error) error

SignIn returns a SignInError, which wraps the error, with how to sign in again, such as when an API doesn't accept the token, as it's revoked

func (*Source) Token

func (self *Source) Token(ctx context.Context) (*oauth2.Token, error)

Token returns the sign-in's token, which is refreshed, and stored, under the key's credential.Lock, once it has expired. A sign-in which was replaced while it was refreshed, such as when the person signed in again, is used, rather than overwritten. Returns a SignInError when the sign-in is revoked, or expired, and ErrServiceUnavailable when the server refuses the client, such as when its secret is wrong, which signing in again doesn't mend, or the server fails.

Jump to

Keyboard shortcuts

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