oauth2providers

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: MIT Imports: 12 Imported by: 1

README

Go OAuth2 Providers

go-oauth2-providers is a Go library for OAuth2 authentication integration. It provides a unified interface to create OAuth2 provider instances and retrieve user information, and supports multiple providers, including Google, Facebook, and GitHub. It's extensively tested and can be used in projects of any size.

Table of Contents

Installation

To install the go-oauth2-providers package, you can use the go get command:

go get github.com/Zhima-Mochi/go-oauth2-providers

Supported Providers

The go-oauth2-providers package currently supports the following OAuth2 providers:

  • Facebook
  • GitHub
  • Google
  • Line

Each provider implementation includes files such as provider_xxx.go, config_provider.go, options_provider.go, authCodeOption.go, token.go, and user.go, along with other utility files. These files provide the necessary logic and structures for interacting with the respective OAuth2 provider.

Components

The go-oauth2-providers package includes the following components:

  • Auth - The Auth component is the main component of the go-oauth2-providers package. It contains all the necessary information for interacting with an OAuth2 provider, including retrieving the authorization URL, exchanging the authorization code for an access token, and retrieving the user information.

  • Provider - The Provider component is the factory for creating Auth instances. It contains the necessary information for creating an Auth instance, including the provider's name, configuration, and options.

Example

See Example for a simple example of how to use the go-oauth2-providers package.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMissingClientID is returned when the client ID is missing.
	ErrMissingClientID = errors.New("missing client ID")

	// ErrMissingClientSecret is returned when the client secret is missing.
	ErrMissingClientSecret = errors.New("missing client secret")

	// ErrMissingRedirectURL is returned when the redirect URL is missing.
	ErrMissingRedirectURL = errors.New("missing redirect URL")
)

Functions

This section is empty.

Types

type Auth

type Auth interface {
	GetOAuth2AuthCodeURL(ctx context.Context, options ...AuthCodeOption) (url string)
	ExchangeOAuth2AuthCode(ctx context.Context, code string) (token *Token, err error)
	RefreshOAuth2Token(ctx context.Context, refreshToken *Token) (token *Token, err error)
	GetOAuth2UserInfo(ctx context.Context, token *Token) (userInfo UserInfo, err error)
}

func NewOAuth2Auth

func NewOAuth2Auth(provider OAuth2Provider, authConfig AuthConfig) Auth

type AuthCodeOption

type AuthCodeOption struct {
	Key string
	Val string
}

type AuthConfig

type AuthConfig interface {
}

func NewAuthConfig

func NewAuthConfig(opts ...AuthOption) AuthConfig

type AuthOption

type AuthOption func(*authConfig)

type OAuth2Provider

type OAuth2Provider interface {
	// contains filtered or unexported methods
}

func NewOAuth2Provider

func NewOAuth2Provider(providerType ProviderType, providerConfig ProviderConfig) (OAuth2Provider, error)

type ProviderConfig

type ProviderConfig interface {
	AuthCodeURL(state string, opts ...AuthCodeOption) string
	Exchange(ctx context.Context, code string, opts ...AuthCodeOption) (*Token, error)
	TokenSource(ctx context.Context, token *Token) oauth2.TokenSource
	Client(ctx context.Context, token *Token) *http.Client
	// contains filtered or unexported methods
}

func NewProviderConfig

func NewProviderConfig(opts ...ProviderOption) (ProviderConfig, error)

type ProviderOption

type ProviderOption func(*providerConfig)

func WithProviderClientID

func WithProviderClientID(clientID string) ProviderOption

func WithProviderClientSecret

func WithProviderClientSecret(clientSecret string) ProviderOption

func WithProviderRedirectURL

func WithProviderRedirectURL(redirectURL string) ProviderOption

func WithProviderScopes

func WithProviderScopes(scopes []string) ProviderOption

type ProviderType

type ProviderType int
const (
	GoogleOAuth2ProviderType ProviderType = iota
	FacebookOAuth2ProviderType
	LineOAuth2ProviderType
	GithubOAuth2ProviderType
)

func (ProviderType) String

func (t ProviderType) String() string

type Token

type Token = oauth2.Token

type UserInfo

type UserInfo interface {
	GetPictureURL() string
	GetEmail() string
	GetName() string
	GetID() string
	// contains filtered or unexported methods
}

func NewUserInfo

func NewUserInfo() UserInfo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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