gauth

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 8 Imported by: 0

README

GAuth

It's just a library of third-party authorization tools that make it easy to get rid of the cumbersome third-party login SDKs.

GitHub Go Reference

Table of Contents

Introduction

Providing a tool library for Go programs to enable third-party authorization login. This library encapsulates the cumbersome process of integrating third-party logins into a simple function call, making login easier.More third-party authorization are under development.

Currently Supported

  • Github
  • Google
  • Facebook
  • Slack
  • Linkedin

Getting Started

// create authorization request
authRequest, err := gauth.New().
Source("github").
ClientId("your_client_id").
ClientSecret("your_client_secret").
RedirectUrl("http://localhost:8080/auth/github/callback").
Build()

// generate authorization URL		
authorizeUrl, err := authRequest.Authorize("state")

// After authorization login, it will return login information.
response, err := authRequest.Login(callback)

More documentation will be updated on website

Inspiration

The project inspiration mainly comes from:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthFailed           = errors.New("auth failed")
	ErrGetAccessToken       = errors.New("get access token error")
	ErrGetUserInfo          = errors.New("get user info error")
	ErrIllegalStatus        = errors.New("illegal status error")
	ErrNotImplemented       = errors.New("not implemented")
	ErrClientIdNotFound     = errors.New("client id is required")
	ErrClientSecretNotFound = errors.New("client secret is required")
	ErrSourceNotFound       = errors.New("auth source is required")
)

Functions

func Register

func Register(source string, factory AuthRequestFactory)

Types

type AuthCallback

type AuthCallback struct {
	Code              string `json:"code" schema:"code"`
	AuthCode          string `json:"auth_code" schema:"auth_code"`
	State             string `json:"state" schema:"state"`
	AuthorizationCode string `json:"authorization_code" schema:"authorization_code"`
	OauthToken        string `json:"oauth_token" schema:"oauth_token"`
	OauthVerifier     string `json:"oauth_verifier" schema:"oauth_verifier"`
}

type AuthRequest

type AuthRequest interface {
	Authorize(state string) (string, error)
	Login(callback AuthCallback) (AuthResponse, error)
	GetAccessToken(callback AuthCallback) (AuthToken, error)
	GetUserInfo(token AuthToken) (AuthUser, error)
	Revoke(token AuthToken) error
}

type AuthRequestBuilder

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

func New

func New() *AuthRequestBuilder

func (*AuthRequestBuilder) Build

func (b *AuthRequestBuilder) Build() (AuthRequest, error)

func (*AuthRequestBuilder) ClientId

func (b *AuthRequestBuilder) ClientId(clientId string) *AuthRequestBuilder

func (*AuthRequestBuilder) ClientSecret

func (b *AuthRequestBuilder) ClientSecret(clientSecret string) *AuthRequestBuilder

func (*AuthRequestBuilder) RedirectUrl

func (b *AuthRequestBuilder) RedirectUrl(redirectUrl string) *AuthRequestBuilder

func (*AuthRequestBuilder) Source

func (b *AuthRequestBuilder) Source(source string) *AuthRequestBuilder

type AuthRequestFactory

type AuthRequestFactory interface {
	NewAuthRequest(*config.AuthConfig) (AuthRequest, error)
}

type AuthResponse

type AuthResponse struct {
	Data interface{} `json:"data"`
}

type AuthToken

type AuthToken struct {
	AccessToken            string `json:"access_token"`
	ExpireIn               int    `json:"expire_in"`
	RefreshToken           string `json:"refresh_token"`
	RefreshTokenExpireIn   int    `json:"refresh_token_expire_in"`
	Uid                    string `json:"uid"`
	OpenId                 string `json:"open_id"`
	AccessCode             string `json:"access_code"`
	UnionId                string `json:"union_id"`
	Scope                  string `json:"scope"`                    // Google
	TokenType              string `json:"token_type"`               // Google
	IdToken                string `json:"id_token"`                 // Google
	MacAlgorithm           string `json:"mac_algorithm"`            // Xiao Mi
	MacKey                 string `json:"mac_key"`                  // Xiao Mi
	Code                   string `json:"code"`                     // Work WeChat
	SnapshotUser           bool   `json:"snapshot_user"`            // WeChat Official Account - Available for web authorization login
	OauthToken             string `json:"oauth_token"`              // Twitter
	OauthTokenSecret       string `json:"oauth_token_secret"`       // Twitter
	UserId                 string `json:"user_id"`                  // Twitter
	ScreenName             string `json:"screen_name"`              // Twitter
	OauthCallbackConfirmed *bool  `json:"oauth_callback_confirmed"` // Twitter
}

type AuthUser

type AuthUser struct {
	UID          string         `json:"uid"`
	Username     string         `json:"username"`
	Nickname     string         `json:"nickname"`
	Avatar       string         `json:"avatar"`
	Blog         string         `json:"blog"`
	Company      string         `json:"company"`
	Location     string         `json:"location"`
	Email        string         `json:"email"`
	Remark       string         `json:"remark"`
	Gender       AuthUserGender `json:"gender"`
	Source       string         `json:"source"`
	Token        AuthToken      `json:"token"`
	RawUserInfo  string         `json:"raw_user_info"`
	SnapshotUser bool           `json:"snapshot_user"`
}

type AuthUserGender

type AuthUserGender int8
const (
	GenderMale    AuthUserGender = 1
	GenderFemale  AuthUserGender = 0
	GenderUnknown AuthUserGender = -1
)

func GetRealGender added in v0.0.2

func GetRealGender(originalGender string) AuthUserGender

type DefaultAuthRequest

type DefaultAuthRequest struct {
	AuthRequest

	Source config.AuthSource
	// contains filtered or unexported fields
}

func NewDefaultAuthRequest

func NewDefaultAuthRequest(config *config.AuthConfig, source config.AuthSource,
	authRequest AuthRequest) *DefaultAuthRequest

func (*DefaultAuthRequest) AccessTokenUrl added in v0.0.3

func (r *DefaultAuthRequest) AccessTokenUrl(code string) string

func (*DefaultAuthRequest) Authorize

func (r *DefaultAuthRequest) Authorize(state string) (string, error)

func (*DefaultAuthRequest) DoPostAuthorizationCode

func (r *DefaultAuthRequest) DoPostAuthorizationCode(code string) (string, error)

func (*DefaultAuthRequest) GetScopes

func (r *DefaultAuthRequest) GetScopes(separator string, encode bool, defaultScopes []string) string

func (*DefaultAuthRequest) Login

func (r *DefaultAuthRequest) Login(callback AuthCallback) (AuthResponse, error)

func (*DefaultAuthRequest) Revoke

func (r *DefaultAuthRequest) Revoke(token AuthToken) error

Directories

Path Synopsis
adapters

Jump to

Keyboard shortcuts

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