request

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 6 Imported by: 1

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, uV url.Values, style AuthHeaderStyle)

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

Style must be AuthHeaderStyleParams, otherwise it does nothing.

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) Password

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

func (*Auth) RawRequest

func (a *Auth) RawRequest(ctx context.Context, 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
}

type AuthorizationCodeConfig

type AuthorizationCodeConfig struct {
	Code        string
	RedirectURI string

	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