corner

package module
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 7 Imported by: 0

README

corner

  • OAUTH2 GRPC Interceptor
  • OAUTH2 Gin-Gonic Middleware

publish

➜ git tag <version>
➜ git push origin --tags
➜ GOPROXY=proxy.golang.org go list -m github.com/bb-labs/corner@<version>

Documentation

Index

Constants

View Source
const (
	AuthCodeHeader          = "x-auth-code"
	AuthTokenHeader         = "authorization"
	AuthTokenHeaderInternal = "id_token"
	AuthRefreshHeader       = "x-auth-refresh"
)
View Source
const (
	AppleProviderURL = "https://appleid.apple.com"
)

OIDC specific provider URLs

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthHeaders added in v0.2.0

type AuthHeaders struct {
	AuthCode    string
	AuthToken   string
	AuthRefresh string
}

func GetAuthHeaders added in v0.1.8

func GetAuthHeaders(headers Headers) AuthHeaders

type AuthInterceptor

type AuthInterceptor struct {
	Providers []*Provider
}

AuthInterceptor provides various middleware that authenticate requests using the given providers.

func New added in v0.2.0

func New(providers ...*Provider) *AuthInterceptor

New returns a new AuthInterceptor that uses the given providers to authenticate requests.

func (*AuthInterceptor) GinAuthenticator added in v0.2.0

func (cb *AuthInterceptor) GinAuthenticator(ctx *gin.Context)

AuthMiddleware returns a new middleware that performs per-request auth.

func (*AuthInterceptor) UnaryServerInterceptor added in v0.2.0

func (cb *AuthInterceptor) UnaryServerInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

UnaryServerInterceptor returns a new grpc unary server interceptor that authenticates requests using the given providers.

type Config added in v0.2.1

type Config struct {

	// Client credentials
	ClientID     string
	ClientSecret string

	// Skip various checks
	SkipChecks bool
	// contains filtered or unexported fields
}

Config represents the configuration for an OpenID Connect provider.

type Headers added in v0.2.0

type Headers map[string][]string

type Provide

type Provide interface {
	Verify(ctx context.Context) (bool, error)
	Redeem(ctx context.Context, code string) (context.Context, error)
	Refresh(ctx context.Context) (context.Context, error)
}

Provide implements various steps of the OpenID Connect flow.

type Provider

type Provider struct {
	*oidc.Provider
	*oidc.IDTokenVerifier
	*oauth2.Config
	// contains filtered or unexported fields
}

Provider represents an OpenID Connect provider, with client credentials.

func NewAppleProvider added in v0.2.0

func NewAppleProvider(ctx context.Context, config Config) (*Provider, error)

NewAppleProvider returns a new Apple Provider.

func (*Provider) Redeem

func (p *Provider) Redeem(ctx context.Context, code string) (*oauth2.Token, error)

Redeem exchanges the OAuth2 authentication token for an ID token

func (*Provider) Refresh

func (p *Provider) Refresh(ctx context.Context, refresh string) (*oauth2.Token, error)

Refresh exchanges the OAuth2 refresh token for an ID token

func (*Provider) Verify

func (p *Provider) Verify(ctx context.Context, token string) (*oidc.IDToken, error)

Jump to

Keyboard shortcuts

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