auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderGitHub = "github"
	ProviderOIDC   = "oidc"
)

Variables

This section is empty.

Functions

func GenerateProviders

func GenerateProviders(
	ctx context.Context,
	config Config,
	redirectURL string,
) (pp map[string]Provider, err error)

func GetClaimsFromRequest

func GetClaimsFromRequest(r *http.Request) (claims *jwt.Claims, ok bool)

Types

type Auth

type Auth struct {
	JWT       jwt.Service
	Providers map[string]Provider
}

func (*Auth) CallBack

func (a *Auth) CallBack() http.HandlerFunc

CallBack is the handler called after login.

It:

1. Fetches the accessToken 2. Fetches some user info and wrap them in a JWT token 3. Store the JWT token in a cookie for the browser.

func (*Auth) Login

func (a *Auth) Login() http.HandlerFunc

Login is the handler that redirect to the authentication page of the OAuth Provider.

func (*Auth) Logout

func (a *Auth) Logout() http.HandlerFunc

func (*Auth) Middleware

func (a *Auth) Middleware(next http.Handler) http.Handler

type Config

type Config struct {
	Providers []ProviderConfig `yaml:"providers"`
}

type OIDCClaims

type OIDCClaims struct {
	jwt.RegisteredClaims
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Provider

type Provider struct {
	Name string
	Type ProviderType
	*oauth2.Config

	OIDCProvider *oidc.Provider
}

type ProviderConfig

type ProviderConfig struct {
	Type         ProviderType `yaml:"type"`
	Name         string       `yaml:"name"`
	ClientID     string       `yaml:"clientID"`
	ClientSecret string       `yaml:"clientSecret"`
	Endpoint     string       `yaml:"endpoint"`
}

type ProviderType

type ProviderType string

Jump to

Keyboard shortcuts

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