oauth

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func With

func With(client restapi.Connector, opts ...Option) restapi.Authorizer

With implements fallback auth strategy, it choose the desired strategy depends on provided configuration options.

1. OAuth2 Resource Owner Password Grant is default and recommended strategy. This strategy requires definition of * Client Access Key, see oauth.Access(...) * Client Secret Key, see oauth.Secret(...) * Client Secret Digest, also known as OAuth Client Secrets, see oauth.Digest(...)

2. OAuth2 Authorization Code Grant strategy is used when only single pair of access/secret key is provided. It allows usage of username and password * Client Access Key, see oauth.Access(...) * Client Secret Key, see oauth.Secret(...)

3. Finally, it falls back explicit token token definition

func WithClientID

func WithClientID(client restapi.Connector, opts ...Option) restapi.Authorizer

WithClientID executes OAuth2 Resource Owner Password Grant It uses access/secret key pair to authenticate client

  auth := oauth2.WithClientID(
		restapi.New(...),
		oauth2.Access(...),
		oauth2.Secret(...),
	)

	client := restapi.New(
		restapi.Auth(auth),
		restapi.Endpoint("https://privx.example.com"),
	)

	rolestore.New(client)

func WithCredential

func WithCredential(client restapi.Connector, opts ...Option) restapi.Authorizer

WithCredential executes OAuth2 Authorization Code Grant It uses access/secret key pair to authenticate client

  auth := oauth2.WithCredential(
		oauth2.Access(...),
		oauth2.Secret(...),
		oauth2.Transport(...),
	)

	client := restapi.New(
		restapi.Auth(auth),
		restapi.Endpoint("https://privx.example.com"),
	)

	rolestore.New(client)

func WithToken

func WithToken(token string) restapi.Authorizer

WithToken uses explicitly defined JWT to authenticate client. Add a 'Bearer ' prefix to the token when passing it to WithToken.

Types

type AccessToken

type AccessToken struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    uint   `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	// contains filtered or unexported fields
}

AccessToken contains OAuth2 access token information.

type Option

type Option func(*tAuth) *tAuth

Option is configuration applied to the client

func Access

func Access(access string) Option

Access setups client access key

func Digest

func Digest(oauthAccess, oauthSecret string) Option

Digest setups client secret digest

func Secret

func Secret(secret string) Option

Secret setups clients secret key

func UseConfigFile

func UseConfigFile(path string) Option

UseConfigFile setup credential from tol file

func UseCookies added in v1.34.0

func UseCookies() Option

func UseEnvironment

func UseEnvironment() Option

UseEnvironment setup credential from environment variables

Jump to

Keyboard shortcuts

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