oauth2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationCodeGrantType string = "authorization_code"
	ClientCredentialsGrantType string = "client_credentials"
	ImplicitGrantType          string = "implicit"
	PasswordGrantType          string = "password"
	RefreshTokenGrantType      string = "refresh_token"
	JWTBearerGrantType         string = "urn:ietf:params:oauth:grant-type:jwt-bearer"
)

grant types

View Source
const (
	ClientSecretBasicAuthMethod string = "client_secret_basic"
	ClientSecretPostAuthMethod  string = "client_secret_post"
)

auth methods

View Source
const CodeVerifierLength = 43
View Source
const OpenIDConfigurationPath = "/.well-known/openid-configuration"

Variables

View Source
var CodeChallengeEncoder = base64.RawURLEncoding

Functions

func FetchOpenIDConfiguration

func FetchOpenIDConfiguration(ctx context.Context, issuerURL string, hc *http.Client) (request Request, c ServerConfig, err error)

func ParseError

func ParseError(resp *http.Response) error

func RandomString

func RandomString(n int) string

func ReadKey

func ReadKey(location string, hc *http.Client) (jose.JSONWebKey, error)

func RequestToken

func RequestToken(
	ctx context.Context,
	cconfig ClientConfig,
	sconfig ServerConfig,
	hc *http.Client,
	opts ...RequestTokenOption,
) (request Request, response TokenResponse, err error)

func SignJWT

func SignJWT(claims map[string]interface{}, key jose.JSONWebKey) (string, error)

func WithAssertion

func WithAssertion(assertion string) func(*RequestTokenParams)

func WithAuthorizationCode

func WithAuthorizationCode(code string) func(*RequestTokenParams)

func WithCodeVerifier

func WithCodeVerifier(codeVerifier string) func(*RequestTokenParams)

func WithRedirectURL

func WithRedirectURL(url string) func(*RequestTokenParams)

func WithStandardClaims

func WithStandardClaims(extra map[string]interface{}, serverConfig ServerConfig) map[string]interface{}

Types

type ClientConfig

type ClientConfig struct {
	IssuerURL    string
	GrantType    string
	ClientID     string
	ClientSecret string
	Scopes       []string
	AuthMethod   string
	PKCE         bool
	NoPKCE       bool
	Insecure     bool
	ResponseType []string
	ResponseMode string
	Username     string
	Password     string
	RefreshToken string
	Assertion    string
	SigningKey   string
}

type Error

type Error struct {
	StatusCode int    `json:"-"`
	TraceID    string `json:"-"`

	ErrorCode   string `json:"error,omitempty"`
	Description string `json:"error_description,omitempty"`
	Hint        string `json:"error_hint,omitempty"`
	Cause       string `json:"cause,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type Request

type Request struct {
	Method  string
	URL     *url.URL
	Headers map[string][]string
	Form    url.Values
}

func RequestAuthorization

func RequestAuthorization(addr string, cconfig ClientConfig, sconfig ServerConfig) (r Request, codeVerifier string, err error)

func WaitForCallback

func WaitForCallback(addr string) (request Request, err error)

func (*Request) Get

func (r *Request) Get(key string) string

type RequestTokenOption

type RequestTokenOption func(*RequestTokenParams)

type RequestTokenParams

type RequestTokenParams struct {
	Code         string
	CodeVerifier string
	RedirectURL  string
	Assertion    string
}

type ServerConfig

type ServerConfig struct {
	Issuer                            string   `json:"issuer"`
	SupportedGrantTypes               []string `json:"grant_types_supported"`
	SupportedResponseTypes            []string `json:"response_types_supported"`
	SupportedTokenEndpointAuthMethods []string `json:"token_endpoint_auth_methods_supported"`
	SupportedScopes                   []string `json:"scopes_supported"`
	SupportedResponseModes            []string `json:"response_modes_supported"`
	AuthorizationEndpoint             string   `json:"authorization_endpoint"`
	TokenEndpoint                     string   `json:"token_endpoint"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken     string `json:"access_token,omitempty"`
	ExpiresIn       int64  `json:"expires_in,omitempty"`
	IDToken         string `json:"id_token,omitempty"`
	IssuedTokenType string `json:"issued_token_type,omitempty"`
	RefreshToken    string `json:"refresh_token,omitempty"`
	Scope           string `json:"scope,omitempty"`
	TokenType       string `json:"token_type,omitempty"`
}

func NewTokenResponseFromForm

func NewTokenResponseFromForm(f url.Values) TokenResponse

Jump to

Keyboard shortcuts

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