oauth2

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(cfg *Config, w http.ResponseWriter, r *http.Request) (model.UserInfo, error)

Authenticate after coming back from the oauth flow. Verify the state parameter againt the state cookie from the request.

func ConstructorList

func ConstructorList() []string

ConstructorList returns the names of all registered constructor

func GetConstructor

func GetConstructor(name string) func(cfg *Config) goth.Provider

func Logout

func Logout(res http.ResponseWriter, req *http.Request) error

Logout invalidates a user session.

func ProviderList

func ProviderList() []string

ProviderList returns the names of all registered provider

func Register

func Register(name string, newi func(cfg *Config) goth.Provider)

func SetCookieStore

func SetCookieStore(secret string)

func SetSessionStore

func SetSessionStore(store sessions.Store)

func StartFlow

func StartFlow(cfg *Config, w http.ResponseWriter, r *http.Request) error

StartFlow by redirecting the user to the login provider. A state parameter to protect against cross-site request forgery attacks is randomly generated and stored in a cookie

Types

type Config

type Config struct {
	// ClientID is the application's ID.
	ClientID string

	// ClientSecret is the application's secret.
	ClientSecret string

	// RedirectURL is the URL to redirect users going through
	// the OAuth flow, after the resource owner's URLs.
	RedirectURI string

	// Scope specifies optional requested permissions, this is a *space* separated list.
	Scope string

	Extra map[string]string

	// The oauth provider
	Provider goth.Provider

	ProviderName string
	// contains filtered or unexported fields
}

Config describes a typical 3-legged OAuth2 flow, with both the client application information and the server's endpoint URLs.

func (*Config) GetProvider

func (cfg *Config) GetProvider() goth.Provider

func (*Config) GetRedirectURI added in v0.1.5

func (cfg *Config) GetRedirectURI() string

func (*Config) GetScopes

func (cfg *Config) GetScopes() []string

func (*Config) InitProvider

func (cfg *Config) InitProvider() error

func (*Config) NewProvider

func (cfg *Config) NewProvider() (p goth.Provider, err error)

func (*Config) SetProvider

func (cfg *Config) SetProvider(provider goth.Provider) *Config

func (*Config) SetRedirectURI added in v0.1.5

func (cfg *Config) SetRedirectURI(redirectURI string) *Config

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager has the responsibility to handle the user user requests in an oauth flow. It has to pick the right configuration and start the oauth redirecting.

func NewManager

func NewManager() *Manager

NewManager creates a new Manager

func (*Manager) AddConfig

func (manager *Manager) AddConfig(providerName string, opts map[string]string) error

AddConfig for a provider

func (*Manager) GetConfigFromRequest

func (manager *Manager) GetConfigFromRequest(r *http.Request) (*Config, error)

GetConfigFromRequest returns the oauth configuration matching the current path. The configuration name is taken from the last path segment.

func (*Manager) GetConfigs

func (manager *Manager) GetConfigs() map[string]*Config

GetConfigs of the manager

func (*Manager) Handle

func (manager *Manager) Handle(w http.ResponseWriter, r *http.Request) (
	startedFlow bool,
	authenticated bool,
	userInfo model.UserInfo,
	err error)

Handle is managing the oauth flow. Dependent on the code parameter of the url, the oauth flow is started or the call is interpreted as the redirect callback and the token exchange is done. Return parameters:

startedFlow - true, if this was the initial call to start the oauth flow
authenticated - if the authentication was successful or not
userInfo - the user info from the provider in case of a successful authentication
err - an error

Directories

Path Synopsis
provider
nging
Package nging implements the OAuth2 protocol for authenticating users through nging.
Package nging implements the OAuth2 protocol for authenticating users through nging.

Jump to

Keyboard shortcuts

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