gooauth

package module
v0.0.0-...-5432c58 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

go-oauth2-login

Golang实现第三方登录

Documentation

Index

Constants

This section is empty.

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 HTTPClientWithFallBack

func HTTPClientWithFallBack(h *http.Client) *http.Client

HTTPClientWithFallBack to be used in all fetch operations.

func UseProviders

func UseProviders(viders ...Provider)

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

Types

type Provider

type Provider interface {
	ProviderType() ProviderType
	GetAuthorizeURL(state string) string
	FetchToken(code string) (*oauth2.Token, string, error)
	FetchUser(token *oauth2.Token, openid string) (User, error)
}

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

func GetProvider

func GetProvider(pType ProviderType) (Provider, error)

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

type ProviderType

type ProviderType string
const (
	PROVIDER_WECHAT ProviderType = "wechat"
)

type Providers

type Providers map[ProviderType]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 User

type User struct {
	RawData           map[string]interface{}
	ProviderType      ProviderType
	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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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