doauth

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package doauth is the DigitalOcean OAuth2 client: authorize URL, code exchange, refresh and revoke.

Index

Constants

View Source
const DefaultBase = "https://cloud.digitalocean.com"

DefaultBase is the DigitalOcean cloud host that serves the OAuth endpoints.

View Source
const Scope = "read write"

Scope asks for read and write so the control plane can create and delete droplets.

Variables

View Source
var ErrRejected = errors.New("doauth: provider rejected the grant")

ErrRejected means DigitalOcean refused the grant (bad code, spent or revoked refresh token).

Functions

func Challenge

func Challenge(verifier string) string

Challenge is the S256 challenge of a verifier.

func NewVerifier

func NewVerifier() (string, error)

NewVerifier returns an RFC 7636 verifier from 32 random bytes.

Types

type Client

type Client struct {
	Base    string
	HTTP    *http.Client
	Timeout time.Duration
}

Client talks to one DigitalOcean OAuth host. Zero Base uses DefaultBase.

func (Client) AuthorizeURL

func (c Client) AuthorizeURL(clientID, redirectURI, state, challenge string) string

AuthorizeURL is the page the operator's browser must open.

func (Client) Exchange

func (c Client) Exchange(ctx context.Context, clientID, secret, redirectURI, code, verifier string) (Tokens, error)

Exchange trades an authorization code for tokens.

func (Client) Refresh

func (c Client) Refresh(ctx context.Context, clientID, secret, refresh string) (Tokens, error)

Refresh spends a refresh token; DigitalOcean rotates it, so the caller must store the new one.

func (Client) Revoke

func (c Client) Revoke(ctx context.Context, token string) error

Revoke invalidates an access token on DigitalOcean's side.

type Tokens

type Tokens struct {
	Access    string
	Refresh   string
	ExpiresIn time.Duration
}

Tokens is one token response. ExpiresIn is zero when the provider sent none.

Jump to

Keyboard shortcuts

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