auth

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("authentication timed out")

ErrTimeout is returned when polling the server for the granted token has timed out.

Functions

func IsTimeoutErr

func IsTimeoutErr(err error) bool

IsTimeoutErr checks if the given error is for the case where the device flow has expired.

Types

type Config

type Config struct {
	ClientID  string
	AuthURL   *url.URL
	UserAgent string
	Scopes    []string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(httpClient *http.Client) *Config

func NewConfigWithOptions

func NewConfigWithOptions(httpClient *http.Client, opts ...ConfigOpt) (*Config, error)

func (*Config) Do

func (c *Config) Do(ctx context.Context, req *http.Request, v interface{}) (*opsmngr.Response, error)

func (*Config) GetToken

func (c *Config) GetToken(ctx context.Context, deviceCode string) (*Token, *opsmngr.Response, error)

GetToken gets a device token.

func (*Config) NewRequest

func (c *Config) NewRequest(ctx context.Context, method, urlStr string, v url.Values) (*http.Request, error)

func (*Config) PollToken

func (c *Config) PollToken(ctx context.Context, code *DeviceCode) (*Token, *opsmngr.Response, error)

PollToken polls the server until an access token is granted or denied.

func (*Config) RefreshToken

func (c *Config) RefreshToken(ctx context.Context, token string) (*Token, *opsmngr.Response, error)

RefreshToken takes a refresh token and gets a new access token.

func (*Config) RegistrationConfig

func (c *Config) RegistrationConfig(ctx context.Context) (*RegistrationConfig, *opsmngr.Response, error)

RegistrationConfig retrieves the config used for registration.

func (*Config) RequestCode

func (c *Config) RequestCode(ctx context.Context) (*DeviceCode, *opsmngr.Response, error)

RequestCode initiates the authorization flow by requesting a code.

func (*Config) RevokeToken

func (c *Config) RevokeToken(ctx context.Context, token, tokenTypeHint string) (*opsmngr.Response, error)

RevokeToken takes an access or refresh token and revokes it.

type ConfigOpt

type ConfigOpt func(*Config) error

func SetAuthURL

func SetAuthURL(bu string) ConfigOpt

SetAuthURL is a config option for setting the base URL.

func SetClientID

func SetClientID(clientID string) ConfigOpt

SetClientID is a config option for setting the ClientID.

func SetScopes

func SetScopes(scopes []string) ConfigOpt

SetScopes is a config option for setting the Scopes.

func SetUserAgent

func SetUserAgent(ua string) ConfigOpt

SetUserAgent is a config option for setting the user agent.

func SetWithRaw

func SetWithRaw() ConfigOpt

SetWithRaw is a client option for getting raw atlas server response within Response structure.

type DeviceCode

type DeviceCode struct {
	UserCode        string `json:"user_code"`        //nolint:tagliatelle // UserCode is the code presented to users
	VerificationURI string `json:"verification_uri"` //nolint:tagliatelle // VerificationURI is the URI where users will need to confirm the code
	DeviceCode      string `json:"device_code"`      //nolint:tagliatelle // DeviceCode is the internal code to confirm the status of the flow
	ExpiresIn       int    `json:"expires_in"`       //nolint:tagliatelle // ExpiresIn when the code will expire
	Interval        int    `json:"interval"`         // Interval how often to verify the status of the code
	// contains filtered or unexported fields
}

DeviceCode holds information about the authorization-in-progress.

type RegistrationConfig

type RegistrationConfig struct {
	RegistrationURL string `json:"registrationUrl"`
}

type Token

type Token struct {
	AccessToken  string `json:"access_token"`  //nolint:tagliatelle // used as in the API
	RefreshToken string `json:"refresh_token"` //nolint:tagliatelle // used as in the API
	Scope        string `json:"scope"`
	IDToken      string `json:"id_token"`   //nolint:tagliatelle // used as in the API
	TokenType    string `json:"token_type"` //nolint:tagliatelle // used as in the API
	ExpiresIn    int    `json:"expires_in"` //nolint:tagliatelle // used as in the API
	Expiry       time.Time
}

func (*Token) SetAuthHeader

func (t *Token) SetAuthHeader(r *http.Request)

func (*Token) Valid

func (t *Token) Valid() bool

type TokenSource

type TokenSource interface {
	// Token returns a token or an error.
	// Token must be safe for concurrent use by multiple goroutines.
	// The returned Token must not be modified.
	Token() (*Token, error)
}

A TokenSource is anything that can return a token.

Jump to

Keyboard shortcuts

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