provider

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingClientID     = errors.New("no client id provided")
	ErrMissingClientSecret = errors.New("no client secret provided")
)
View Source
var ErrInvalidSetup error = errors.New("providers.oauth.auth-url, providers.oauth.token-url, providers.oauth.user-url, providers.oauth.token-style must be set")
View Source
var ErrMissingIssuerUrl = errors.New("no issuer url provided")

Functions

func GetUserFromBytes

func GetUserFromBytes(jsonBytes []byte, UserPath string) (string, error)

GetUser extracts a UserID located at the (dot notation) path (UserPath) in the json io.Reader of the UserURL

func GetUserFromReader

func GetUserFromReader(r io.Reader, UserPath string) (string, error)

Types

type OAuth

type OAuth 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"`
	ClientIDFile     string           `long:"client-id-file" env:"CLIENT_ID_FILE" description:"Path to a file containing the client id"`
	ClientSecret     string           `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
	ClientSecretFile string           `long:"client-secret-file" env:"CLIENT_SECRET_FILE" description:"Path to a file containing the client secret"`
	TokenStyle       types.TokenStyle `` /* 148-byte string literal not displayed */

	OAuthProviderConfig
}

OAuth provider

func (OAuth) ExchangeCode

func (o OAuth) ExchangeCode(redirectURI, code string) (string, error)

ExchangeCode exchanges the given redirect uri and code for a token

func (OAuth) GetLoginURL

func (o OAuth) GetLoginURL(redirectURI, state string, forcePrompt bool) string

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

func (OAuth) GetUser

func (o OAuth) GetUser(token, UserPath string) (string, error)

GetUser uses the given token and returns a UserID

func (OAuth) Name

func (o OAuth) Name() string

Name returns the name of the provider

func (*OAuth) Setup

func (o *OAuth) Setup() error

Setup performs validation and setup

type OAuthProviderConfig

type OAuthProviderConfig struct {
	Scopes   []string `long:"scope" env:"SCOPE" env-delim:"," default:"profile" default:"email" description:"Scopes"`
	Prompt   string   `long:"prompt" env:"PROMPT" description:"Optional prompt query"`
	Resource string   `long:"resource" env:"RESOURCE" description:"Optional resource indicator"`

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

OAuthProviderConfig is a provider using the oauth2 library

func (*OAuthProviderConfig) ConfigCopy

func (p *OAuthProviderConfig) 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 (*OAuthProviderConfig) OAuthExchangeCode

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

OAuthExchangeCode provides a base "ExchangeCode" for proiders using OAauth2

func (*OAuthProviderConfig) OAuthGetLoginURL

func (p *OAuthProviderConfig) OAuthGetLoginURL(redirectURI, state string, forcePrompt bool) 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"`
	ClientIDFile     string `long:"client-id-file" env:"CLIENT_ID_FILE" description:"Path to a file containing the client id"`
	ClientSecret     string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
	ClientSecretFile string `long:"client-secret-file" env:"CLIENT_SECRET_FILE" description:"Path to a file containing the client secret"`

	OAuthProviderConfig
	// 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, forcePrompt bool) string

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

func (OIDC) GetUser

func (o OIDC) GetUser(token, UserPath string) (string, 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, forcePrompt bool) string
	ExchangeCode(redirectURI, code string) (string, error)
	GetUser(token, UserPath string) (string, error)
	Setup() error
}

Provider is used to authenticate users

type Providers

type Providers struct {
	OIDC  OIDC  `group:"OIDC Provider" namespace:"oidc" env-namespace:"OIDC"`
	OAuth OAuth `group:"Generic OAuth2 Provider" namespace:"oauth" env-namespace:"OAUTH"`
}

Providers contains all the implemented providers

func (*Providers) GetAll

func (p *Providers) GetAll() []Provider

type User

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

User is the authenticated user

Jump to

Keyboard shortcuts

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