mcm_google_sso

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: MIT Imports: 9 Imported by: 0

README

GoLang Google SSO handlers

[CircleCI]

Package for creating authorization with Google on GoLang, can be use in any frameworks. Have protection from csrf attack.

Usage

go get github.com/PxyUp/google-sso-handlers


type ConfigController interface {
	GetHost() string
	GetClientId() string
	GetClientSecret() string
	GetRandomBytesLength() int
}

type RedirectsController interface {
	GetSuccessRedirectUrl(token string) string
	GetFailedRedirectUrl(errCode int, err error) string
	GetCallbackUrl() string
}

type UserController interface {
	UserInfoFn(user *mcm_google_sso.GoogleOauthUser) (string, error)
}

func initRouter() error {
	oauth, err := mcm_google_sso.NewGoogleOAuth(ConfigController, RedirectsController, UserController).GetGoogleAuthHandler()
    	if err != nil {
    		return nil, err
    	}
        http.HandleFunc("/google/login", oauth.LoginHandler)
	http.HandleFunc("/google/callback", oauth.CallbackHandler) // callback url from redirects
        log.Fatal(http.ListenAndServe(":8080", nil))
}

Examples

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SECURE_ERROR = errors.New("Length of the secure bytes must be more than 10")
)

Functions

This section is empty.

Types

type ConfigController

type ConfigController interface {
	GetHost() string
	GetClientId() string
	GetClientSecret() string
	GetRandomBytesLength() int
}

type GoogleAuthHandlers

type GoogleAuthHandlers struct {
	LoginHandler    func(w http.ResponseWriter, r *http.Request)
	CallbackHandler func(w http.ResponseWriter, r *http.Request)
}

type GoogleOAuth

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

func (*GoogleOAuth) GetGoogleAuthHandler

func (c *GoogleOAuth) GetGoogleAuthHandler() (*GoogleAuthHandlers, error)

type GoogleOauthUser

type GoogleOauthUser struct {
	Name    string `json:"name"`
	Picture string `json:"picture"`
	Email   string `json:"email"`
}

type RedirectsController

type RedirectsController interface {
	GetSuccessRedirectUrl(token string) string
	GetFailedRedirectUrl(errCode int, err error) string
	GetCallbackUrl() string
}

type UserController

type UserController interface {
	UserInfoFn(user *GoogleOauthUser) (string, error)
}

Jump to

Keyboard shortcuts

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