oauth2

package
v0.0.0-...-8b94866 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustQueryString

func MustQueryString(d any) string

func QueryString

func QueryString(d any) (queryString string, err error)

Types

type AccessTokenRequest

type AccessTokenRequest struct {
	GrantType GrantType `schema:"grant_type"`
	// Code is required in 'code' flow
	Code string `schema:"code"`
	// Username is required in 'password' flow
	Username string `schema:"username"`
	// Password is used in 'password' flow
	Password string `schema:"password"`
}

type AuthorizationRequest

type AuthorizationRequest struct {
	ResponseType string `schema:"response_type"`
	ClientID     string `schema:"client_id"`
	RedirectURI  string `schema:"redirect_uri,omitempty"`
	Scope        string `schema:"scope,omitepmty"`
	State        string `schema:"state,omitempty"`
}

func AuthorizationRequestFromURLValues

func AuthorizationRequestFromURLValues(values url.Values) (*AuthorizationRequest, error)

type AuthorizationResponse

type AuthorizationResponse struct {
	Code  string `schema:"code"`
	State string `schema:"state"`
}

type ErrorCode

type ErrorCode string
const (
	// ErrorInvalidRequest 4.1.2.1, 4.2.2.1, 5.2
	ErrorInvalidRequest ErrorCode = "invalid_request"
	// ErrorUnauthorizedClient 4.1.2.1, 4.2.2.1, 5.2
	ErrorUnauthorizedClient ErrorCode = "unauthorized_client"
	// ErrorAccessDenied 4.1.2.1, 4.2.2.1
	ErrorAccessDenied ErrorCode = "access_denied"
	// ErrorUnsupportedResponseType 4.1.2.1, 4.2.2.1
	ErrorUnsupportedResponseType ErrorCode = "unsupported_response_type"
	// ErrorInvalidScope 4.1.2.1, 4.2.2.1, 5.2
	ErrorInvalidScope ErrorCode = "invalid_scope"
	// ErrorServerError 4.1.2.1, 4.2.2.1
	ErrorServerError ErrorCode = "server_error"
	// ErrorTemporarilyUnavailable 4.1.2.1, 4.2.2.1
	ErrorTemporarilyUnavailable ErrorCode = "temporarily_unavailable"
	// ErrorInvalidClient 5.2
	ErrorInvalidClient ErrorCode = "invalid_client"
	// ErrorInvalidGrant 5.2
	ErrorInvalidGrant ErrorCode = "invalid_grant"
	// ErrorUnsupportedGrantType 5.2
	ErrorUnsupportedGrantType ErrorCode = "unsupported_grant_type"
)

func (ErrorCode) HTTPStatusCode

func (errorCode ErrorCode) HTTPStatusCode() int

type ErrorResponse

type ErrorResponse struct {
	Error            ErrorCode `json:"error" schema:"error"`
	ErrorDescription string    `json:"error_description,omitempty" schema:"error_description,omitempty"`
	ErrorURI         string    `json:"error_uri,omitempty" schema:"error_uri,omitempty"`
	State            string    `json:"-" schema:"state,omitempty"`
}

func (ErrorResponse) SwaggerDoc

func (ErrorResponse) SwaggerDoc() map[string]string

type GrantType

type GrantType string
const (
	GrantTypeAuthorizationCode GrantType = "authorization_code"
	GrantTypeClientCredentials GrantType = "client_credentials"
	GrantTypePassword          GrantType = "password"
	GrantTypeRefreshToken      GrantType = "refresh_token"

	GrantTypeUnknown GrantType = ""
)

func GrantTypeFromString

func GrantTypeFromString(s string) GrantType

type Responder

type Responder struct {
	// contains filtered or unexported fields
}

func RespondTo

func RespondTo(w http.ResponseWriter) Responder

func (Responder) ErrInvalidClientBasicAuthorization

func (r Responder) ErrInvalidClientBasicAuthorization(realmName string, errorDesc string)

func (Responder) Error

func (r Responder) Error(errorData ErrorResponse)

func (Responder) ErrorCode

func (r Responder) ErrorCode(errorCode ErrorCode)

func (Responder) ErrorWithHTTPStatusCode

func (r Responder) ErrorWithHTTPStatusCode(errorData ErrorResponse, httpStatusCode int)

func (Responder) TokenCustom

func (r Responder) TokenCustom(tokenData any)

type ResponseType

type ResponseType string
const (
	ResponseTypeCode  ResponseType = "code"
	ResponseTypeToken ResponseType = "token"

	ResponseTypeUnknown ResponseType = ""
)

func ResponseTypeFromString

func ResponseTypeFromString(s string) ResponseType

func (ResponseType) String

func (responseType ResponseType) String() string

type TokenResponse

type TokenResponse struct {
	// The access token issued by the authorization server.
	AccessToken string `json:"access_token" schema:"access_token"`
	// The type of the token issued as described in
	// Section 7.1.  Value is case insensitive.
	TokenType TokenType `json:"token_type" schema:"token_type"`
	// The lifetime in seconds of the access token.  For
	// example, the value "3600" denotes that the access token will
	// expire in one hour from the time the response was generated.
	// If omitted, the authorization server SHOULD provide the
	// expiration time via other means or document the default value.
	ExpiresIn int64 `json:"expires_in,omitempty" schema:"expires_in,omitempty"`
	// The refresh token, which can be used to obtain new
	// access tokens using the same authorization grant as described
	// in Section 6.
	RefreshToken string `json:"refresh_token,omitempty" schema:"refresh_token,omitempty"`
	// The scope of the access token as described by Section 3.3.
	Scope string `json:"scope,omitempty" schema:"scope,omitempty"`

	State string `json:"-" schema:"state,omitempty"`
}

TokenResponse is used on successful authorization. The authorization server issues an access token and optional refresh token, and constructs the response by adding the following parameters to the entity-body of the HTTP response with a 200 (OK) status code

func (TokenResponse) SwaggerDoc

func (TokenResponse) SwaggerDoc() map[string]string

type TokenType

type TokenType string
const (
	TokenTypeBearer TokenType = "bearer"
)

TokenTypeBearer NOTE: token types are case-insensitive

Jump to

Keyboard shortcuts

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