soth

package
v0.0.0-...-f828163 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NoAuthUrlErrorMessage = "an AuthURL has not been set"

Variables

This section is empty.

Functions

func ClearProviders

func ClearProviders()

ClearProviders will remove all providers currently in use. This is useful, mostly, for testing purposes.

func ContextForClient

func ContextForClient(h *http.Client) context.Context

ContextForClient provides a context for use with oauth2.

func UseProviders

func UseProviders(viders ...Provider)

UseProviders adds a list of available providers for use with Soth. Can be called multiple times. If you pass the same provider more than once, the last will be used.

Types

type Params

type Params interface {
	Get(string) string
}

Params is used to pass data to sessions for authorization. An existing implementation, and the one most likely to be used, is `url.Values`.

type Provider

type Provider interface {
	Name() string
	SetName(name string)
	BeginAuth(state string) (Session, error)
	UnmarshalSession(string) (Session, error)
	FetchUser(Session) (User, error)
	Debug(bool)
	RefreshToken(refreshToken string) (*oauth2.Token, error) // Get new access token based on the refresh token
	RefreshTokenAvailable() bool                             // Refresh token is provided by auth provider or not
}

Provider needs to be implemented for each 3rd party authentication provider e.g. Facebook, Twitter, etc...

func GetProvider

func GetProvider(name string) (Provider, error)

GetProvider returns a previously created provider. If Soth has not been told to use the named provider it will return an error.

type Providers

type Providers map[string]Provider

Providers is list of known/available providers.

func GetProviders

func GetProviders() Providers

GetProviders returns a list of all the providers currently in use.

type Session

type Session interface {
	// GetAuthURL returns the URL for the authentication end-point for the provider.
	GetAuthURL() (string, error)
	// Marshal generates a string representation of the Session for storing between requests.
	Marshal() string
	// Authorize should validate the data from the provider and return an access token
	// that can be stored for later access to the provider.
	Authorize(Provider, Params) (string, error)
}

Session needs to be implemented as part of the provider package. It will be marshaled and persisted between requests to "tie" the start and the end of the authorization process with a 3rd party provider.

type User

type User struct {
	RawData           map[string]interface{}
	Provider          string
	Email             string
	Name              string
	FirstName         string
	LastName          string
	NickName          string
	Description       string
	UserID            string
	AvatarURL         string
	Location          string
	AccessToken       string
	AccessTokenSecret string
	RefreshToken      string
	ExpiresAt         time.Time
	IDToken           string
}

User contains the information common amongst most OAuth and OAuth2 providers. All the "raw" data from the provider can be found in the `RawData` field.

func (*User) Into

func (u *User) Into() *models.User

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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