providers

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const AudPrefixForGQCommitment = "OPENPUBKEY-PKTOKEN:"

Variables

View Source
var CommitTypesEnum = struct {
	NONCE_CLAIM CommitType
	AUD_CLAIM   CommitType
	GQ_BOUND    CommitType
}{
	NONCE_CLAIM: CommitType{Claim: "nonce", GQCommitment: false},
	AUD_CLAIM:   CommitType{Claim: "aud", GQCommitment: false},
	GQ_BOUND:    CommitType{Claim: "", GQCommitment: true},
}

Functions

func CreateGQBoundToken

func CreateGQBoundToken(ctx context.Context, idToken []byte, op OpenIdProvider, cicHash string) ([]byte, error)

func CreateGQToken

func CreateGQToken(ctx context.Context, idToken []byte, op OpenIdProvider) ([]byte, error)

func FindAvaliablePort

func FindAvaliablePort(redirectURIs []string) (*url.URL, net.Listener, error)

FindAvaliablePort attempts to open a listener on localhost until it finds one or runs out of redirectURIs to try

func GenCIC

func GenCIC(t *testing.T) *clientinstance.Claims

func GenCICExtra

func GenCICExtra(t *testing.T, extraClaims map[string]any) *clientinstance.Claims

Types

type BrowserOpenIdProvider

type BrowserOpenIdProvider interface {
	OpenIdProvider
	HookHTTPSession(h http.HandlerFunc)
}

type CommitType

type CommitType struct {
	Claim        string
	GQCommitment bool
}

type DefaultProviderVerifier

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

func NewProviderVerifier

func NewProviderVerifier(issuer string, options ProviderVerifierOpts) *DefaultProviderVerifier

Creates a new ProviderVerifier with required fields

issuer: Is the OpenID provider issuer as seen in ID token e.g. "https://accounts.google.com" commitmentClaim: the ID token payload claim name where the cicHash was stored during issuance

func (*DefaultProviderVerifier) Issuer

func (v *DefaultProviderVerifier) Issuer() string

func (*DefaultProviderVerifier) VerifyIDToken

func (v *DefaultProviderVerifier) VerifyIDToken(ctx context.Context, idToken []byte, cic *clientinstance.Claims) error

type GithubOp

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

func NewGithubOp

func NewGithubOp(tokenURL string, token string) *GithubOp

func NewGithubOpFromEnvironment

func NewGithubOpFromEnvironment() (*GithubOp, error)

func (*GithubOp) Issuer

func (g *GithubOp) Issuer() string

func (*GithubOp) PublicKeyByJTK

func (g *GithubOp) PublicKeyByJTK(ctx context.Context, jtk string) (*discover.PublicKeyRecord, error)

func (*GithubOp) PublicKeyByKeyId

func (g *GithubOp) PublicKeyByKeyId(ctx context.Context, keyID string) (*discover.PublicKeyRecord, error)

func (*GithubOp) PublicKeyByToken

func (g *GithubOp) PublicKeyByToken(ctx context.Context, token []byte) (*discover.PublicKeyRecord, error)

func (*GithubOp) RequestTokens

func (g *GithubOp) RequestTokens(ctx context.Context, cic *clientinstance.Claims) ([]byte, error)

func (*GithubOp) VerifyIDToken

func (g *GithubOp) VerifyIDToken(ctx context.Context, idt []byte, cic *clientinstance.Claims) error

type GitlabOp

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

func NewGitlabOp

func NewGitlabOp(issuer string, tokenEnvVar string) *GitlabOp

func NewGitlabOpFromEnvironment

func NewGitlabOpFromEnvironment(tokenEnvVar string) *GitlabOp

func NewGitlabOpFromEnvironmentDefault

func NewGitlabOpFromEnvironmentDefault() *GitlabOp

func (*GitlabOp) Issuer

func (g *GitlabOp) Issuer() string

func (*GitlabOp) PublicKeyByJTK

func (g *GitlabOp) PublicKeyByJTK(ctx context.Context, jtk string) (*discover.PublicKeyRecord, error)

func (*GitlabOp) PublicKeyByKeyId

func (g *GitlabOp) PublicKeyByKeyId(ctx context.Context, keyID string) (*discover.PublicKeyRecord, error)

func (*GitlabOp) PublicKeyByToken

func (g *GitlabOp) PublicKeyByToken(ctx context.Context, token []byte) (*discover.PublicKeyRecord, error)

func (*GitlabOp) RequestTokens

func (g *GitlabOp) RequestTokens(ctx context.Context, cic *clientinstance.Claims) ([]byte, error)

func (*GitlabOp) VerifyIDToken

func (g *GitlabOp) VerifyIDToken(ctx context.Context, idt []byte, cic *clientinstance.Claims) error

type GoogleOp

type GoogleOp struct {
	ClientID     string
	ClientSecret string
	Scopes       []string
	RedirectURIs []string
	GQSign       bool
	// contains filtered or unexported fields
}

func (*GoogleOp) HookHTTPSession

func (g *GoogleOp) HookHTTPSession(h http.HandlerFunc)

HookHTTPSession provides a means to hook the HTTP Server session resulting from the OpenID Provider sending an authcode to the OIDC client by redirecting the user's browser with the authcode supplied in the URI. If this hook is set, it will be called after the receiving the authcode but before send an HTTP response to the user. The code which sets this hook can choose what HTTP response to server to the user.

We use this so that we can redirect the user web browser window to the MFA Cosigner URI after the user finishes the OIDC Auth flow. This method is only available to browser based providers.

func (*GoogleOp) Issuer

func (g *GoogleOp) Issuer() string

func (*GoogleOp) PublicKeyByJTK

func (g *GoogleOp) PublicKeyByJTK(ctx context.Context, jtk string) (*discover.PublicKeyRecord, error)

func (*GoogleOp) PublicKeyByKeyId

func (g *GoogleOp) PublicKeyByKeyId(ctx context.Context, keyID string) (*discover.PublicKeyRecord, error)

func (*GoogleOp) PublicKeyByToken

func (g *GoogleOp) PublicKeyByToken(ctx context.Context, token []byte) (*discover.PublicKeyRecord, error)

func (*GoogleOp) RequestTokens

func (g *GoogleOp) RequestTokens(ctx context.Context, cic *clientinstance.Claims) ([]byte, error)

func (*GoogleOp) VerifyIDToken

func (g *GoogleOp) VerifyIDToken(ctx context.Context, idt []byte, cic *clientinstance.Claims) error

type GoogleOptions

type GoogleOptions struct {
	ClientID     string
	ClientSecret string
	Issuer       string // This should almost always be "https://accounts.google.com"
	Scopes       []string
	RedirectURIs []string
	GQSign       bool
}

func GetDefaultGoogleOpOptions

func GetDefaultGoogleOpOptions() *GoogleOptions

type MockProvider

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

func (*MockProvider) Issuer

func (m *MockProvider) Issuer() string

func (*MockProvider) PublicKeyByJTK

func (m *MockProvider) PublicKeyByJTK(ctx context.Context, jtk string) (*discover.PublicKeyRecord, error)

func (*MockProvider) PublicKeyByKeyId

func (m *MockProvider) PublicKeyByKeyId(ctx context.Context, keyID string) (*discover.PublicKeyRecord, error)

func (*MockProvider) PublicKeyByToken

func (m *MockProvider) PublicKeyByToken(ctx context.Context, token []byte) (*discover.PublicKeyRecord, error)

func (*MockProvider) RequestTokens

func (m *MockProvider) RequestTokens(ctx context.Context, cic *clientinstance.Claims) ([]byte, error)

func (*MockProvider) VerifyIDToken

func (m *MockProvider) VerifyIDToken(ctx context.Context, idt []byte, cic *clientinstance.Claims) error

type MockProviderOpts

type MockProviderOpts struct {
	Issuer     string
	ClientID   string
	GQSign     bool
	NumKeys    int
	CommitType CommitType
	// We keep VerifierOpts as a variable separate to let us test failures
	// where the mock op does something which causes a verification failure
	VerifierOpts ProviderVerifierOpts
}

func DefaultMockProviderOpts

func DefaultMockProviderOpts() MockProviderOpts

type OpenIdProvider

type OpenIdProvider interface {
	RequestTokens(ctx context.Context, cic *clientinstance.Claims) ([]byte, error)
	PublicKeyByKeyId(ctx context.Context, keyID string) (*discover.PublicKeyRecord, error)
	PublicKeyByJTK(ctx context.Context, jtk string) (*discover.PublicKeyRecord, error)
	PublicKeyByToken(ctx context.Context, token []byte) (*discover.PublicKeyRecord, error)
	// Returns the OpenID provider issuer as seen in ID token e.g. "https://accounts.google.com"
	Issuer() string
	VerifyIDToken(ctx context.Context, idt []byte, cic *clientinstance.Claims) error
}

Interface for interacting with the OP (OpenID Provider)

func NewGoogleOp

func NewGoogleOp() OpenIdProvider

NewGoogleOp creates a Google OP (OpenID Provider) using the default configurations options. It uses the OIDC Relying Party (Client) setup by the OpenPubkey project.

func NewGoogleOpWithOptions

func NewGoogleOpWithOptions(opts *GoogleOptions) OpenIdProvider

NewGoogleOpWithOptions creates a Google OP with configuration specified using an options struct. This is useful if you want to use your own OIDC Client or override the configuration.

func NewMockProvider

NewMockProvider creates a new mock provider with a random signing key and a random key ID. It returns the provider, the mock backend, and the ID token template. Tests can use the mock backend to look up keys issued by the mock provider. Tests can use the ID token template to create ID tokens and test the provider's behavior when verifying incorrectly set ID Tokens.

type ProviderVerifierOpts

type ProviderVerifierOpts struct {
	// If ClientID is specified, then verification will require that the ClientID
	// be present in the audience ("aud") claim of the PK token payload
	ClientID string
	// Describes the place where the cicHash is committed to in the the ID token.
	// For instance the nonce payload claim name where the cicHash was stored during issuance
	CommitType CommitType
	// Specifies whether to skip the Client ID check, defaults to false
	SkipClientIDCheck bool
	// Custom function for discovering public key of Provider
	DiscoverPublicKey *discover.PublicKeyFinder
	// Allows for successful verification of expired tokens
	SkipExpirationCheck bool
	// Only allows GQ signatures, a provider signature under any other algorithm
	// is seen as an error
	GQOnly bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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