Documentation
¶
Index ¶
- Variables
- func AuthHeader(req *http.Request, clientID, clientSecret string, style AuthHeaderStyle)
- func AuthParams(clientID, clientSecret string, req *http.Request, style AuthHeaderStyle)
- func RawRequest(req *http.Request, client *http.Client) ([]byte, error)
- func SetBearerAuth(r *http.Request, token string)
- type Auth
- func (a *Auth) AuthRequest(ctx context.Context, uValues url.Values, cfg AuthRequestConfig) ([]byte, error)
- func (a *Auth) AuthorizationCode(ctx context.Context, cfg AuthorizationCodeConfig) ([]byte, error)
- func (a *Auth) ClientCredentials(ctx context.Context, cfg ClientCredentialsConfig) ([]byte, error)
- func (a *Auth) Password(ctx context.Context, cfg PassswordConfig) ([]byte, error)
- func (a *Auth) RawRequest(req *http.Request) ([]byte, error)
- func (a *Auth) RefreshToken(ctx context.Context, cfg RefreshTokenConfig) ([]byte, error)
- type AuthHeaderStyle
- type AuthRequestConfig
- type AuthorizationCodeConfig
- type ClientCredentialsConfig
- type PassswordConfig
- type RefreshTokenConfig
Constants ¶
This section is empty.
Variables ¶
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 SetBearerAuth ¶
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 (*Auth) AuthorizationCode ¶
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 ¶
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) RefreshToken ¶
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
}