auth

package
v0.27.7 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostedGrantType = "urn:ietf:params:oauth:grant-type:device_code"
)

HostedGrantType grant type for device flow on Hosted

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthFlowInfo

type AuthFlowInfo struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

AuthFlowInfo holds information for the OAuth 2.0 authorization flow

type Claims

type Claims struct {
	Audience interface{} `json:"aud"`
}

Claims used when validating the access token

type DeviceAuthorizationFlow

type DeviceAuthorizationFlow struct {
	HTTPClient HTTPClient
	// contains filtered or unexported fields
}

DeviceAuthorizationFlow implements the OAuthFlow interface, for the Device Authorization Flow.

func NewDeviceAuthorizationFlow

func NewDeviceAuthorizationFlow(config internal.DeviceAuthProviderConfig) (*DeviceAuthorizationFlow, error)

NewDeviceAuthorizationFlow returns device authorization flow client

func (*DeviceAuthorizationFlow) GetClientID

func (d *DeviceAuthorizationFlow) GetClientID(ctx context.Context) string

GetClientID returns the provider client id

func (*DeviceAuthorizationFlow) RequestAuthInfo

func (d *DeviceAuthorizationFlow) RequestAuthInfo(ctx context.Context) (AuthFlowInfo, error)

RequestAuthInfo requests a device code login flow information from Hosted

func (*DeviceAuthorizationFlow) WaitToken

WaitToken waits user's login and authorize the app. Once the user's authorize it retrieves the access token from Hosted's endpoint and validates it before returning

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient http client interface for API calls

type OAuthFlow

type OAuthFlow interface {
	RequestAuthInfo(ctx context.Context) (AuthFlowInfo, error)
	WaitToken(ctx context.Context, info AuthFlowInfo) (TokenInfo, error)
	GetClientID(ctx context.Context) string
}

OAuthFlow represents an interface for authorization using different OAuth 2.0 flows

func NewOAuthFlow

func NewOAuthFlow(ctx context.Context, config *internal.Config, isLinuxDesktopClient bool) (OAuthFlow, error)

NewOAuthFlow initializes and returns the appropriate OAuth flow based on the management configuration

It starts by initializing the PKCE.If this process fails, it resorts to the Device Code Flow, and if that also fails, the authentication process is deemed unsuccessful

On Linux distros without desktop environment support, it only tries to initialize the Device Code Flow

type PKCEAuthorizationFlow

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

PKCEAuthorizationFlow implements the OAuthFlow interface for the Authorization Code Flow with PKCE.

func NewPKCEAuthorizationFlow

func NewPKCEAuthorizationFlow(config internal.PKCEAuthProviderConfig) (*PKCEAuthorizationFlow, error)

NewPKCEAuthorizationFlow returns new PKCE authorization code flow.

func (*PKCEAuthorizationFlow) GetClientID

func (p *PKCEAuthorizationFlow) GetClientID(_ context.Context) string

GetClientID returns the provider client id

func (*PKCEAuthorizationFlow) RequestAuthInfo

func (p *PKCEAuthorizationFlow) RequestAuthInfo(ctx context.Context) (AuthFlowInfo, error)

RequestAuthInfo requests a authorization code login flow information.

func (*PKCEAuthorizationFlow) WaitToken

WaitToken waits for the OAuth token in the PKCE Authorization Flow. It starts an HTTP server to receive the OAuth token callback and waits for the token or an error. Once the token is received, it is converted to TokenInfo and validated before returning.

type RequestDeviceCodePayload

type RequestDeviceCodePayload struct {
	Audience string `json:"audience"`
	ClientID string `json:"client_id"`
	Scope    string `json:"scope"`
}

RequestDeviceCodePayload used for request device code payload for auth0

type TokenInfo

type TokenInfo struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	IDToken      string `json:"id_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	UseIDToken   bool   `json:"-"`
}

TokenInfo holds information of issued access token

func (TokenInfo) GetTokenToUse

func (t TokenInfo) GetTokenToUse() string

GetTokenToUse returns either the access or id token based on UseIDToken field

type TokenRequestPayload

type TokenRequestPayload struct {
	GrantType    string `json:"grant_type"`
	DeviceCode   string `json:"device_code,omitempty"`
	ClientID     string `json:"client_id"`
	RefreshToken string `json:"refresh_token,omitempty"`
}

TokenRequestPayload used for requesting the auth0 token

type TokenRequestResponse

type TokenRequestResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
	TokenInfo
}

TokenRequestResponse used for parsing Hosted token's response

Jump to

Keyboard shortcuts

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