request

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAuth = &Auth{
	Client: http.DefaultClient,
}

DefaultAuth is a default Auth struct with http.DefaultClient.

Functions

func AuthHeader

func AuthHeader(req *http.Request, clientID, clientSecret string, style AuthHeaderStyle)

AuthHeader is a function to set Authorization header.

Style must be AuthHeaderStyleBasic or AuthHeaderStyleBearerSecret, otherwise it does nothing.

Default style is AuthHeaderStyleBasic.

func AuthParams

func AuthParams(clientID, clientSecret string, req *http.Request, style AuthHeaderStyle)

AuthParams is a function to set Authorization params in url.Values.

Style must be AuthHeaderStyleParams, otherwise it does nothing.

func RawRequest

func RawRequest(req *http.Request, client *http.Client) ([]byte, error)

func SetBearerAuth

func SetBearerAuth(r *http.Request, token string)

SetBearerAuth sets the Authorization header to use Bearer token.

Types

type Auth

type Auth struct {
	// Client is a http client to use. If nil, http.DefaultClient will be used.
	Client *http.Client
}

Auth is a struct to handle flow of OAuth2.

func (*Auth) AuthRequest

func (a *Auth) AuthRequest(ctx context.Context, uValues url.Values, cfg AuthRequestConfig) ([]byte, error)

func (*Auth) AuthorizationCode

func (a *Auth) AuthorizationCode(ctx context.Context, cfg AuthorizationCodeConfig) ([]byte, error)

AuthorizationCode is a function to handle authorization code flow.

Returns a byte array of the response body, if the response status code is 2xx.

func (*Auth) ClientCredentials

func (a *Auth) ClientCredentials(ctx context.Context, cfg ClientCredentialsConfig) ([]byte, error)

RefreshToken is a function to handle refresh token flow.

Returns a byte array of the response body, if the response status code is 2xx.

func (*Auth) Password

func (a *Auth) Password(ctx context.Context, cfg PassswordConfig) ([]byte, error)

func (*Auth) RawRequest

func (a *Auth) RawRequest(req *http.Request) ([]byte, error)

func (*Auth) RefreshToken

func (a *Auth) RefreshToken(ctx context.Context, cfg RefreshTokenConfig) ([]byte, error)

RefreshToken is a function to handle refresh token flow.

Returns a byte array of the response body, if the response status code is 2xx.

type AuthHeaderStyle

type AuthHeaderStyle int

AuthHeaderStyle is a type to set Authorization header style.

const (
	AuthHeaderStyleBasic AuthHeaderStyle = iota
	AuthHeaderStyleBearerSecret
	AuthHeaderStyleParams
)

type AuthRequestConfig

type AuthRequestConfig struct {
	TokenURL string
	ClientID string
	// ClientSecret is optional
	ClientSecret string
	// AuthHeaderStyle is optional. If not set, AuthHeaderStyleBasic will be used.
	AuthHeaderStyle AuthHeaderStyle
	// Scopes for refresh and password flow.
	Scopes []string
}

type AuthorizationCodeConfig

type AuthorizationCodeConfig struct {
	Code        string
	RedirectURL string

	// EndpointParams specifies additional parameters for requests to the token endpoint.
	EndpointParams url.Values

	AuthRequestConfig
}

type ClientCredentialsConfig

type ClientCredentialsConfig struct {
	RefreshToken string

	// EndpointParams specifies additional parameters for requests to the token endpoint.
	EndpointParams url.Values

	AuthRequestConfig
}

type PassswordConfig

type PassswordConfig struct {
	Username string
	Password string

	Scopes []string

	AuthRequestConfig
}

type RefreshTokenConfig

type RefreshTokenConfig struct {
	RefreshToken string

	AuthRequestConfig
}

Jump to

Keyboard shortcuts

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