auth

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: UPL-1.0 Imports: 3 Imported by: 0

Documentation

Overview

Package auth provides functionality and types used for authorization providers.

Index

Constants

View Source
const (
	// BearerToken represents the bearer token authorization scheme that the
	// bearer who holds the access token can access authorized resources.
	//
	// This is used for the on-premise Oracle NoSQL server that authorizes
	// requests by itself, and the Oracle NoSQL cloud simulator.
	BearerToken string = "Bearer"

	// Signature authorization scheme.
	// This is used for NoSQL cloud service that uses OCI IAM for request authorization.
	Signature string = "Signature"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ProviderOptions

type ProviderOptions struct {
	// Timeout specifies the timeout for requests.
	// If not set, or set to a value that is less than 1 millisecond,
	// use the default timeout that depends on the concrete implementation of
	// authorization provider.
	Timeout time.Duration

	// ExpiryWindow specifies a duration of time that determines how far ahead
	// of access token expiry the provider is allowed to renew the access token.
	// If not set, or set to a value that is less than 1 millisecond,
	// use the default expiry window that depends on the concrete implementation
	// of authorization provider.
	// If set to a duration that is greater than the access token's lifetime,
	// the provider does not renew cached tokens.
	ExpiryWindow time.Duration

	// Logger specifies a logger for the provider.
	// If not set, use logger.DefaultLogger by default.
	Logger *logger.Logger

	// HTTPClient specifies an HTTP client for the provider.
	// If not set, use httputil.DefaultHTTPClient by default.
	HTTPClient *httputil.HTTPClient
}

ProviderOptions represents options for an authorization provider.

type Request

type Request interface {
	// Request-dependent value.
	// The authorization provider is supposed to be able to interpret the value.
	Value() string
}

Request is an interface that wraps the request dependent value for an authorization request.

type Token

type Token struct {
	// The access token issued by the authorization server.
	AccessToken string `json:"access_token"`

	// Token type.
	// If not set, this is "Bearer" by default.
	Type string `json:"token_type,omitempty"`

	// The duration of time the access token is granted for.
	// A zero value of ExpiresIn means the access token does not expire.
	ExpiresIn time.Duration `json:"expires_in,omitempty"`

	// The time when the access token expires.
	// A zero value of Expiry means the access token does not expire.
	Expiry time.Time `json:"expiry,omitempty"`
}

Token represents the credentials used to authorize the requests to access protected resources.

func NewToken

func NewToken(accessToken, tokenType string, expiresIn time.Duration) *Token

NewToken creates a token with the specified access token, token type and expiresIn duration.

func NewTokenWithExpiry

func NewTokenWithExpiry(accessToken, tokenType string, expiry time.Time) *Token

NewTokenWithExpiry creates a token with the specified access token, token type and expiry.

func (Token) AuthString

func (t Token) AuthString() string

AuthString returns a string that will be set in the HTTP "Authorization" header.

func (Token) Expired

func (t Token) Expired() bool

Expired checks whether the access token has expired.

func (Token) NeedRefresh

func (t Token) NeedRefresh(expiryWindow time.Duration) bool

NeedRefresh checks whether the access token needs to refresh.

An access token needs to refresh if it is about to expire in a duration of time that is within the specified expiry window.

Directories

Path Synopsis
Package cloudsim provides authorization provider implementations for clients that connect to cloud simulator.
Package cloudsim provides authorization provider implementations for clients that connect to cloud simulator.
Package iam provides authorization provider implementations for clients that connect to cloud via IAM (Oracle Identity and Access Management).
Package iam provides authorization provider implementations for clients that connect to cloud via IAM (Oracle Identity and Access Management).
Package kvstore provides authorization provider implementations for clients that connect to on-premise NoSQL servers.
Package kvstore provides authorization provider implementations for clients that connect to on-premise NoSQL servers.

Jump to

Keyboard shortcuts

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