login

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GoogleOAuthEmailScope = "https://www.googleapis.com/auth/userinfo.email" // WTF to get this

)

Variables

View Source
var (
	// FacebookClientID and FacebookClientSecret are credentials you'll
	// get when you setup OAuth2 logins on the facebook side. You *must*
	// specify these two values.
	FacebookClientID     string
	FacebookClientSecret string
)
View Source
var (
	// GoogleClientID and GoogleClientSecret are credentials you'll get
	// when you setup OAuth2 logins on the google side. You *must*
	// specify these two values.
	GoogleClientID     string
	GoogleClientSecret string
)
View Source
var (
	// The caller should configure these values. Note that the URLs need
	// to be added to your Google and Facebook setups, as allowed
	// referrers.
	Host                  = "https://stop.jetnoise.net"
	RedirectUrlStem       = "/login" // oauth2 callbacks will register  under here
	AfterLoginRelativeUrl = "/"      // where the user finally ends up, after being logged in
	OnSuccessCallback     Oauth2SucessCallback

	// Individual oauth2 systems
	Goauth2  Oauth2er
	Fboauth2 Oauth2er
)

Functions

func Init

func Init()

The caller *must* call this, after they've set the vars above

func NewOauth2Handler

func NewOauth2Handler(oauth2 Oauth2er) func(w http.ResponseWriter, r *http.Request)

Returns a standard requesthandler. When run, it handles the redirect from the oauth2 provider, and if it gets an email address from the provider, will invoke the callback function with it, before redirecting to the provided URL.

Types

type FacebookOauth2

type FacebookOauth2 struct {
	oauth2.Config
}

func NewFacebookOauth2

func NewFacebookOauth2() FacebookOauth2

func (FacebookOauth2) CallbackToEmail

func (fboauth2 FacebookOauth2) CallbackToEmail(r *http.Request) (string, error)

func (FacebookOauth2) GetLoginUrl

func (fboauth2 FacebookOauth2) GetLoginUrl(w http.ResponseWriter, r *http.Request) string

If the user wants to login via facebook, we will redirect them to this URL

func (FacebookOauth2) GetLogoutUrl

func (fboauth2 FacebookOauth2) GetLogoutUrl(w http.ResponseWriter, r *http.Request) string

We don't use this, as we don't have users juggling FB accounts and getting confused the way we do with Google accounts

func (FacebookOauth2) Name

func (fb FacebookOauth2) Name() string

type GoogleOauth2

type GoogleOauth2 struct {
	oauth2.Config
}

func NewGoogleOauth2

func NewGoogleOauth2() GoogleOauth2

func (GoogleOauth2) CallbackToEmail

func (goauth2 GoogleOauth2) CallbackToEmail(r *http.Request) (string, error)

func (GoogleOauth2) GetLoginUrl

func (goauth2 GoogleOauth2) GetLoginUrl(w http.ResponseWriter, r *http.Request) string

func (GoogleOauth2) GetLogoutUrl

func (goauth2 GoogleOauth2) GetLogoutUrl(w http.ResponseWriter, r *http.Request) string

func (GoogleOauth2) Name

func (g GoogleOauth2) Name() string

type Oauth2SucessCallback

type Oauth2SucessCallback func(w http.ResponseWriter, r *http.Request, email string) error

type Oauth2er

type Oauth2er interface {
	Name() string
	GetLoginUrl(w http.ResponseWriter, r *http.Request) string
	GetLogoutUrl(w http.ResponseWriter, r *http.Request) string
	CallbackToEmail(r *http.Request) (string, error)
}

Jump to

Keyboard shortcuts

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