identity

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package identity provides support for making OpenID Connect (OIDC) and OAuth2 authenticated HTTP requests with third party identity providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAuthenticator

func RegisterAuthenticator(name string, ctor AuthenticatorConstructor)

RegisterAuthenticator registers a new Authenticator.

Types

type Authenticator

type Authenticator interface {
	Authenticate(context.Context, string, State) (*oauth2.Token, error)
	Refresh(context.Context, *oauth2.Token, State) (*oauth2.Token, error)
	Revoke(context.Context, *oauth2.Token) error
	Name() string
	UpdateUserInfo(ctx context.Context, t *oauth2.Token, v any) error

	SignIn(w http.ResponseWriter, r *http.Request, state string) error
	SignOut(w http.ResponseWriter, r *http.Request, idTokenHint, authenticateSignedOutURL, redirectToURL string) error
}

Authenticator is an interface representing the ability to authenticate with an identity provider.

func NewAuthenticator

func NewAuthenticator(o oauth.Options) (a Authenticator, err error)

NewAuthenticator returns a new identity provider based on its name.

type AuthenticatorConstructor

type AuthenticatorConstructor func(context.Context, *oauth.Options) (Authenticator, error)

AuthenticatorConstructor makes an Authenticator from the given options.

type Claims

type Claims map[string]any

Claims are JWT claims.

func NewClaimsFromRaw

func NewClaimsFromRaw(raw map[string]json.RawMessage) Claims

NewClaimsFromRaw creates a new Claims map from a map of raw messages.

func (Claims) Claims

func (claims Claims) Claims(v any) error

Claims takes the claims data and fills v.

func (Claims) Flatten

func (claims Claims) Flatten() FlattenedClaims

Flatten flattens the claims to a FlattenedClaims map. For example:

{ "a": { "b": { "c": 12345 } } } => { "a.b.c": [12345] }

func (Claims) ToAnyMap

func (claims Claims) ToAnyMap() map[string]*anypb.Any

ToAnyMap converts the claims into a map of string => any.

func (*Claims) UnmarshalJSON

func (claims *Claims) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the raw json data into the claims object.

type FlattenedClaims

type FlattenedClaims map[string][]any

FlattenedClaims are a set claims flattened into a single-level map.

func NewFlattenedClaimsFromPB

func NewFlattenedClaimsFromPB(m map[string]*structpb.ListValue) FlattenedClaims

NewFlattenedClaimsFromPB creates a new FlattenedClaims from the protobuf struct type.

func (FlattenedClaims) ToPB

func (claims FlattenedClaims) ToPB() map[string]*structpb.ListValue

ToPB converts the flattened claims into a protobuf type.

func (*FlattenedClaims) UnmarshalJSON

func (claims *FlattenedClaims) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into the flattened claims.

type MockProvider

type MockProvider struct {
	AuthenticateResponse oauth2.Token
	AuthenticateError    error
	RefreshResponse      oauth2.Token
	RefreshError         error
	RevokeError          error
	UpdateUserInfoError  error
	SignInError          error
	SignOutError         error
}

MockProvider provides a mocked implementation of the providers interface.

func (MockProvider) Authenticate

Authenticate is a mocked providers function.

func (MockProvider) Name

func (mp MockProvider) Name() string

Name returns the provider name.

func (MockProvider) Refresh

Refresh is a mocked providers function.

func (MockProvider) Revoke

func (mp MockProvider) Revoke(_ context.Context, _ *oauth2.Token) error

Revoke is a mocked providers function.

func (MockProvider) SignIn

func (mp MockProvider) SignIn(_ http.ResponseWriter, _ *http.Request, _ string) error

SignIn is a mocked providers function.

func (MockProvider) SignOut

func (mp MockProvider) SignOut(_ http.ResponseWriter, _ *http.Request, _, _, _ string) error

SignOut is a mocked providers function.

func (MockProvider) UpdateUserInfo

func (mp MockProvider) UpdateUserInfo(_ context.Context, _ *oauth2.Token, _ any) error

UpdateUserInfo is a mocked providers function.

type SessionClaims

type SessionClaims struct {
	Claims
	RawIDToken string
}

SessionClaims are claims that are attached to a session so we can store the raw id token.

func (*SessionClaims) SetRawIDToken

func (claims *SessionClaims) SetRawIDToken(rawIDToken string)

SetRawIDToken sets the raw id token.

type State

type State = identity.State

State is the identity state.

Directories

Path Synopsis
Package identity is a package to avoid a dependency cycle.
Package identity is a package to avoid a dependency cycle.
Package legacymanager contains an identity manager responsible for refreshing sessions and creating users.
Package legacymanager contains an identity manager responsible for refreshing sessions and creating users.
Package manager contains an identity manager responsible for refreshing sessions and creating users.
Package manager contains an identity manager responsible for refreshing sessions and creating users.
Package oauth provides support for making OAuth2 authorized and authenticated HTTP requests, as specified in RFC 6749.
Package oauth provides support for making OAuth2 authorized and authenticated HTTP requests, as specified in RFC 6749.
apple
Package apple implements OpenID Connect for apple
Package apple implements OpenID Connect for apple
github
Package github implements OAuth2 based authentication for github
Package github implements OAuth2 based authentication for github
Package oidc implements a generic OpenID Connect provider.
Package oidc implements a generic OpenID Connect provider.
auth0
Package auth0 implements OpenID Connect for auth0
Package auth0 implements OpenID Connect for auth0
azure
Package azure implements OpenID Connect for Microsoft Azure
Package azure implements OpenID Connect for Microsoft Azure
cognito
Package cognito provides support for AWS Cognito
Package cognito provides support for AWS Cognito
gitlab
Package gitlab implements OpenID Connect for Gitlab
Package gitlab implements OpenID Connect for Gitlab
google
Package google implements OpenID Connect for Google and GSuite.
Package google implements OpenID Connect for Google and GSuite.
okta
Package okta implements OpenID Connect for okta
Package okta implements OpenID Connect for okta
onelogin
Package onelogin implements OpenID Connect for OneLogin
Package onelogin implements OpenID Connect for OneLogin
ping
Package ping implements OpenID Connect for Ping
Package ping implements OpenID Connect for Ping

Jump to

Keyboard shortcuts

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