provider

package
v0.0.0-...-e43f98d Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericOAuth

type GenericOAuth struct {
	AuthURL      string   `long:"auth-url" env:"AUTH_URL" description:"Auth/Login URL"`
	TokenURL     string   `long:"token-url" env:"TOKEN_URL" description:"Token URL"`
	UserURL      string   `long:"user-url" env:"USER_URL" description:"URL used to retrieve user info"`
	ClientID     string   `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
	ClientSecret string   `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
	Scopes       []string `long:"scope" env:"SCOPE" env-delim:"," default:"profile" default:"email" description:"Scopes"`
	TokenStyle   string   `` /* 148-byte string literal not displayed */

	OAuthProvider
}

GenericOAuth provider

func (*GenericOAuth) ExchangeCode

func (o *GenericOAuth) ExchangeCode(redirectURI, code string) (string, error)

ExchangeCode exchanges the given redirect uri and code for a token

func (*GenericOAuth) GetLoginURL

func (o *GenericOAuth) GetLoginURL(redirectURI, state string) string

GetLoginURL provides the login url for the given redirect uri and state

func (*GenericOAuth) GetUser

func (o *GenericOAuth) GetUser(token string) (User, error)

GetUser uses the given token and returns a complete provider.User object

func (*GenericOAuth) Name

func (o *GenericOAuth) Name() string

Name returns the name of the provider

func (*GenericOAuth) Setup

func (o *GenericOAuth) Setup() error

Setup performs validation and setup

type Google

type Google struct {
	ClientID     string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
	ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
	Scope        string
	Prompt       string `long:"prompt" env:"PROMPT" default:"select_account" description:"Space separated list of OpenID prompt options"`

	LoginURL *url.URL
	TokenURL *url.URL
	UserURL  *url.URL
}

Google provider

func (*Google) ExchangeCode

func (g *Google) ExchangeCode(redirectURI, code string) (string, error)

ExchangeCode exchanges the given redirect uri and code for a token

func (*Google) GetLoginURL

func (g *Google) GetLoginURL(redirectURI, state string) string

GetLoginURL provides the login url for the given redirect uri and state

func (*Google) GetUser

func (g *Google) GetUser(token string) (User, error)

GetUser uses the given token and returns a complete provider.User object

func (*Google) Name

func (g *Google) Name() string

Name returns the name of the provider

func (*Google) Setup

func (g *Google) Setup() error

Setup performs validation and setup

type OAuthProvider

type OAuthProvider struct {
	Resource string `long:"resource" env:"RESOURCE" description:"Optional resource indicator"`

	Config *oauth2.Config
	// contains filtered or unexported fields
}

OAuthProvider is a provider using the oauth2 library

func (*OAuthProvider) ConfigCopy

func (p *OAuthProvider) ConfigCopy(redirectURI string) oauth2.Config

ConfigCopy returns a copy of the oauth2 config with the given redirectURI which ensures the underlying config is not modified

func (*OAuthProvider) OAuthExchangeCode

func (p *OAuthProvider) OAuthExchangeCode(redirectURI, code string) (*oauth2.Token, error)

OAuthExchangeCode provides a base "ExchangeCode" for proiders using OAauth2

func (*OAuthProvider) OAuthGetLoginURL

func (p *OAuthProvider) OAuthGetLoginURL(redirectURI, state string) string

OAuthGetLoginURL provides a base "GetLoginURL" for proiders using OAauth2

type OIDC

type OIDC struct {
	IssuerURL    string `long:"issuer-url" env:"ISSUER_URL" description:"Issuer URL"`
	ClientID     string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
	ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`

	OAuthProvider
	// contains filtered or unexported fields
}

OIDC provider

func (*OIDC) ExchangeCode

func (o *OIDC) ExchangeCode(redirectURI, code string) (string, error)

ExchangeCode exchanges the given redirect uri and code for a token

func (*OIDC) GetLoginURL

func (o *OIDC) GetLoginURL(redirectURI, state string) string

GetLoginURL provides the login url for the given redirect uri and state

func (*OIDC) GetUser

func (o *OIDC) GetUser(token string) (User, error)

GetUser uses the given token and returns a complete provider.User object

func (*OIDC) Name

func (o *OIDC) Name() string

Name returns the name of the provider

func (*OIDC) Setup

func (o *OIDC) Setup() error

Setup performs validation and setup

type Provider

type Provider interface {
	Name() string
	GetLoginURL(redirectURI, state string) string
	ExchangeCode(redirectURI, code string) (string, error)
	GetUser(token string) (User, error)
	Setup() error
}

Provider is used to authenticate users

type Providers

type Providers struct {
	Google       Google       `group:"Google Provider" namespace:"google" env-namespace:"GOOGLE"`
	OIDC         OIDC         `group:"OIDC Provider" namespace:"oidc" env-namespace:"OIDC"`
	GenericOAuth GenericOAuth `group:"Generic OAuth2 Provider" namespace:"generic-oauth" env-namespace:"GENERIC_OAUTH"`
}

Providers contains all the implemented providers

type User

type User struct {
	Email string `json:"email"`
}

User is the authenticated user

Jump to

Keyboard shortcuts

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