sso

package
v0.0.0-...-3407765 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoogleHandlerErrWrap = "GOOGLE SSO HANDLER ERROR :"
)
View Source
const (
	HandlerTypeGoogle = "GOOGLE"
)

Variables

View Source
var (
	ErrorInvalidGoogleJWTClaim = fmt.Errorf("%s %s", GoogleHandlerErrWrap, "Could not Verify JWT Claim")
	ErrorExpiredGoogleJWTClaim = fmt.Errorf("%s %s", GoogleHandlerErrWrap, "Auth Token is Expired")
	ErrorMissingGoogleRSAKey   = fmt.Errorf("%s %s", GoogleHandlerErrWrap, "RSA Key could not be found")
)
View Source
var (
	// ErrorUnsupportedHandlerType : if the header sso_type returns something we don't like
	ErrorUnsupportedHandlerType = fmt.Errorf("unsupported SSO Handler , please ensure you only use the following sso types %s", supportedSSOHandlers)
	// ErrorHandlerIsNotConfiguredProperly : if one of the handlers is nil
	ErrorHandlerIsNotConfiguredProperly = fmt.Errorf("this is a backend problem , please contact admin . SSO handler is not configured properly")
)
View Source
var (
	ErrorUnauthorized = errors.New("Unauthorized")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// GoogleClientID : google client id for your app
	GoogleClientID string
}

Config : configuration for sso handlers

type Google

type Google struct {
	ClientID string
}

Google : A 0 depedency Google SSO handler that adapts perfectly to any Framework as long as you can provide the http.Request Object

func (*Google) ValidateGoogleJWT

func (g *Google) ValidateGoogleJWT(tokenString string) (GoogleClaims, error)

func (*Google) VerifyUser

func (g *Google) VerifyUser(req http.Header) (res *entity.Account, err error)

type GoogleClaims

type GoogleClaims struct {
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	FirstName     string `json:"given_name"`
	LastName      string `json:"family_name"`
	jwt.StandardClaims
}

GoogleClaims : google jwt claims we get back from the token

type Handler

type Handler interface {
	// VerifyUser : this method shall not write to method body !!
	// use this method to authenticate a client using an sso provider
	// you're free to choose how you want your header data to look like
	VerifyUser(req http.Header) (acc *entity.Account, err error)
}

Handler : generic sso handler

func New

func New(config Config) Handler

New : create a new instance of an SSO Handler (this will contain all the handler types (google , apple , ...etc)) see sso.Manager

When you call the VerifyUser method , the Manager will call the appropriate handler type by checking the header For sso_type , if that is supported then it will execute whatever code exists for that handler

IE if sso_type == "GOOGLE" then it will execute the sso.Google Handler

type Manager

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

Manager : Acts like an adapter pattern . It adapts to the same interface

But under the hood it can call the correct sso handler implementaton ie google , facebook , apple ..etc

func (*Manager) VerifyUser

func (m *Manager) VerifyUser(req http.Header) (acc *entity.Account, err error)

VerifyUser : Calls the appropriate Handler to do verification

Jump to

Keyboard shortcuts

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