providers

package
v0.0.0-...-ae1d368 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnectProvider

func NewConnectProvider(connectConfig ConnectConfig) auth.Provider

NewConnectProvider creates a ConnectID OAuth2 provider instance

func NewGitHubProvider

func NewGitHubProvider(githubConfig GithubConfig) auth.Provider

NewGitHubProvider creates a GitHub OAuth2 provider instance

func NewOAuth2Provider

func NewOAuth2Provider(config Config) auth.Provider

Types

type Config

type Config struct {
	// Enabled determines whether the auth is enabled
	Enabled bool `param:"desc=Auth type enabled;default=false"`

	// ClientID is the OAuth2 provider client ID
	ClientID string `param:"desc=Client ID"`
	// ClientSecret is the OAuth2 provider secret
	ClientSecret string `param:"desc=Client secret"`

	// Scopes are a list of scopes to be used during the auth process
	Scopes []string

	// AuthBasePath is the base path for the provider. It will be used when adding
	// paths to the router.
	AuthBasePath string `param:"desc=The base path for the provider"`

	// CallbackURL is the callback URL to be used during the OAuth2 flow
	CallbackURL string `param:"desc=Callback URL;default=/"`
	// LoginSuccessURL is the URL to redirect to when a successful login has occured
	LoginSuccessURL string `param:"desc=Login success redirect URL;default=/"`
	// LogoutSuccessURL is the URL to redirect to when a successful logout has occured
	LogoutSuccessURL string `param:"desc=Logout success redirect URL;default=/"`

	// AuthEndpointURL is the auth endpoint for the OAuth2 provider
	AuthEndpointURL string `param:"desc=The OAuth2 auth URL endpoint;default=/"`
	// TokenEndpointURL is the token endpoint for the OAuth2 provider
	TokenEndpointURL string `param:"desc=The Oauth2 token URL endpoint;default=/"`
	// UserEndpointURL is the user endpoint where the provider will get information about the user
	UserEndpointURL string `param:"desc=The URL to get user information from using the authenticated token;default=/"`

	// SecureCookie determines whether the session cookie is set to be secure (ie, https only)
	SecureCookie bool `param:"desc=Determines the session cookie is secure (HTTPS) only"`
}

Config is the generic OAuth2 config for an OAuth2 provider

func NewConfigFromConnect

func NewConfigFromConnect(connectConfig ConnectConfig) Config

func NewConfigFromGithub

func NewConfigFromGithub(githubConfig GithubConfig) Config

func NewFromConfig

func NewFromConfig(overrideConfig Config) Config

NewFromConfig returns a populated Config object with defaults

type ConnectConfig

type ConnectConfig struct {
	// Enabled determines whether the auth is enabled
	Enabled bool `param:"desc=Auth type enabled;default=false"`

	// ClientID is the Connect client ID. Defaults to the open test example from Connect.
	ClientID string `param:"desc=Client ID;default=telenordigital-connectexample-web"`
	// ClientSecret is the Connect secret
	ClientSecret string `param:"desc=Client secret"`

	// Scopes is a comma separated list of scopes to request
	Scopes string `param:"desc=Scopes to request towards Connect;default=openid,profile,email,phone"`

	// AuthBasePath is the base path for the server Connect endpoint. It will be used when adding
	// paths to the router.
	AuthBasePath string `param:"desc=The base path for the provider;default=/connect"`

	// CallbackURL is the callback URL to be used during the OAuth2 flow
	CallbackURL string `param:"desc=Callback URL;default=http://localhost:8080/connect/oauth2callback"`
	// LoginSuccessURL is the URL to redirect to when a successful login has occured
	LoginSuccessURL string `param:"desc=Login success redirect URL;default=/"`
	// LogoutSuccessURL is the URL to redirect to when a successful logout has occured
	LogoutSuccessURL string `param:"desc=Logout success redirect URL;default=/"`

	// Host is the Connect host environment to be used, defaults to https://connect.staging.telenordigital.com
	Host string `param:"desc=The full host for the Connect environment to be used;default=https://connect.staging.telenordigital.com"`

	// SecureCookie determines whether the session cookie is set to be secure (ie, https only)
	SecureCookie bool `param:"desc=Determines the session cookie is secure (HTTPS) only;default=false"`
}

A simplified Connect specific configuration

type ConnectUserProfile

type ConnectUserProfile struct {
	ID                  string `json:"sub"`
	Name                string `json:"name"`
	Email               string `json:"email"`
	EmailVerified       bool   `json:"email_verified"`
	PhoneNumber         string `json:"phone_number"`
	PhoneVerifiedNumber bool   `json:"phone_number_verified"`
}

ConnectUserProfile contains the Connect profile.

type GithubConfig

type GithubConfig struct {
	// Enabled determines whether the auth is enabled
	Enabled bool `param:"desc=Auth type enabled;default=false"`

	// ClientID is the Github client ID
	ClientID string `param:"desc=Client ID"`
	// ClientSecret is the Github secret
	ClientSecret string `param:"desc=Client secret"`

	// Scopes is a comma separated list of scopes to request
	Scopes string `param:"desc=Scopes to request towards Connect;default=user:read,user:email"`

	// AuthBasePath is the base path for the server github endpoint. It will be used when adding
	// paths to the router.
	AuthBasePath string `param:"desc=The base path for the provider;default=/github"`

	// CallbackURL is the callback URL to be used during the OAuth2 flow
	CallbackURL string `param:"desc=Callback URL;default=http://localhost:8080/github/oauth2callback"`
	// LoginSuccessURL is the URL to redirect to when a successful login has occured
	LoginSuccessURL string `param:"desc=Login success redirect URL;default=/"`
	// LogoutSuccessURL is the URL to redirect to when a successful logout has occured
	LogoutSuccessURL string `param:"desc=Logout success redirect URL;default=/"`

	// SecureCookie determines whether the session cookie is set to be secure (ie, https only)
	SecureCookie bool `param:"desc=Determines the session cookie is secure (HTTPS) only;default=false"`
}

A simplified Connect specific configuration

type GithubUserProfile

type GithubUserProfile struct {
	ID        int64  `json:"id"`
	AvatarURL string `json:"avatarUrl"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	Login     string `json:"login"`
}

GithubUserProfile contains the GitHub profile. It's much bigger, but only the fields used are documented for now.

type OAuth2Provider

type OAuth2Provider struct {
	Config Config // Config is the Provider configuration
	// contains filtered or unexported fields
}

func (*OAuth2Provider) BasePath

func (p *OAuth2Provider) BasePath() string

BasePath returns the OAuth2 base path to be used when adding provider routes

func (*OAuth2Provider) Enabled

func (p *OAuth2Provider) Enabled() bool

func (*OAuth2Provider) Handler

func (p *OAuth2Provider) Handler() http.Handler

Handler returns a handler for the (local) GitHub resource

func (*OAuth2Provider) ServeHTTP

func (p *OAuth2Provider) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is a http.HandleFunc to be attached to your route of choice. It will add a login path, a callback path and a logout path. If it receives an unknown request, it will use the ServerErrorHandleFunc provided in the Authenticator configuration.

func (*OAuth2Provider) SetServerErrorHandlerFunc

func (p *OAuth2Provider) SetServerErrorHandlerFunc(serverErrorFunc func(w http.ResponseWriter, r *http.Request, err auth.AuthError))

func (*OAuth2Provider) SetSessions

func (p *OAuth2Provider) SetSessions(sessions auth.SessionStore)

func (*OAuth2Provider) StartSessionChecker

func (p *OAuth2Provider) StartSessionChecker()

StartSessionChecker launches a profile checker goroutine

Jump to

Keyboard shortcuts

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