oidc

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicClient

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

BasicClient for OIDC.

func NewClient

func NewClient(config *Config) *BasicClient

NewClient returns new BasicClient instance.

func (*BasicClient) Exchange

func (c *BasicClient) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange the auth code for the OAuth2 token.

func (*BasicClient) FormatRequest

func (c *BasicClient) FormatRequest(state string, opts ...oauth2.AuthCodeOption) string

FormatRequest returns a correctly-formatted OIDC request.

func (*BasicClient) UserInfo

func (c *BasicClient) UserInfo(ctx context.Context, token *oauth2.Token) (Claimer, error)

UserInfo returns the user's info.

func (*BasicClient) VerifyIDToken

func (c *BasicClient) VerifyIDToken(ctx context.Context, oauthToken OAuth2Token) (Claimer, error)

VerifyIDToken parses the id_token within the OAuth2 token and verifies it.

type Claimer

type Claimer interface {
	Claims(interface{}) error
}

Claimer is the OIDC id_token.

type Client

type Client interface {
	FormatRequest(state string, opts ...oauth2.AuthCodeOption) string
	Exchange(c context.Context, code string) (*oauth2.Token, error)
	VerifyIDToken(c context.Context, oauthToken OAuth2Token) (Claimer, error)
	UserInfo(ctx context.Context, token *oauth2.Token) (Claimer, error)
}

Client is capable of formatting authorization requests, exchanging the token grant for an access_token and id_token, and verifying id_tokens.

type Config

type Config struct {
	TLSConfig    *tls.Config
	Provider     Provider
	CallbackURL  string
	ClientID     string
	ClientSecret string
	Scopes       []string
}

Config defines configuration for oidc client.

type MockClaimer

type MockClaimer struct {
	ClaimsErr  error
	ClaimsFunc func(interface{}) error
}

MockClaimer can be a mock id_token or a mock UserInfo.

func (*MockClaimer) Claims

func (m *MockClaimer) Claims(i interface{}) error

Claims scans the claims into 'i'.

type MockClient

type MockClient struct {
	AuthRequest string
	OAuthToken  *oauth2.Token
	OAuthErr    error
	IDToken     Claimer
	IDTokenErr  error
	UserInfoVal Claimer
	UserInfoErr error
}

MockClient is a mock OIDC client.

func (*MockClient) Exchange

func (m *MockClient) Exchange(_ context.Context, _ string) (*oauth2.Token, error)

Exchange exchanges the code for an oauth token.

func (*MockClient) FormatRequest

func (m *MockClient) FormatRequest(_ string, options ...oauth2.AuthCodeOption) string

FormatRequest formats the OIDC authorization request.

func (*MockClient) UserInfo

func (m *MockClient) UserInfo(_ context.Context, _ *oauth2.Token) (Claimer, error)

UserInfo returns the user's info.

func (*MockClient) VerifyIDToken

func (m *MockClient) VerifyIDToken(_ context.Context, _ OAuth2Token) (Claimer, error)

VerifyIDToken verifies the id_token inside the OAuth2 token.

type OAuth2Token

type OAuth2Token interface {
	Extra(string) interface{}
	Valid() bool
}

OAuth2Token is the oauth2.Token.

type Provider

type Provider interface {
	Endpoint() oauth2.Endpoint
	Verifier(*oidc.Config) Verifier
	UserInfo(context.Context, oauth2.TokenSource) (*oidc.UserInfo, error)
}

Provider provides discovery of OIDC provider endpoints and also verifies id_tokens.

type ProviderAdapter

type ProviderAdapter struct {
	OP        *oidc.Provider
	TLSConfig *tls.Config
}

ProviderAdapter adapts an *oidc.Provider into an OIDCProvider.

func (*ProviderAdapter) Endpoint

func (o *ProviderAdapter) Endpoint() oauth2.Endpoint

Endpoint returns the OIDC endpoints.

func (*ProviderAdapter) UserInfo

func (o *ProviderAdapter) UserInfo(ctx context.Context, ts oauth2.TokenSource) (*oidc.UserInfo, error)

UserInfo returns the user's info.

func (*ProviderAdapter) Verifier

func (o *ProviderAdapter) Verifier(config *oidc.Config) Verifier

Verifier returns an OIDC verifier.

type Verifier

type Verifier interface {
	Verify(ctx context.Context, rawIDToken string) (*oidc.IDToken, error)
}

Verifier parses and verifies a raw id_token.

Jump to

Keyboard shortcuts

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