blasphem/pkg/auth/provider/provider.go
2022-11-12 16:31:26 -05:00

51 lines
1.3 KiB
Go

package provider
import (
"dynatron.me/x/blasphem/pkg/storage"
)
type Constructor func(storage.Store) (AuthProvider, error)
var Providers = make(map[string]Constructor)
type AuthProvider interface { // TODO: this should include stepping
AuthProviderMetadata
ProviderBase() AuthProviderBase
FlowSchema() []FlowSchemaItem
NewCredData() interface{}
ValidateCreds(reqMap map[string]interface{}) (user ProviderUser, success bool)
}
func Register(providerName string, f func(storage.Store) (AuthProvider, error)) {
Providers[providerName] = f
}
type ProviderUser interface {
AuthProviderMetadata
ProviderUserData() interface{}
}
type AuthProviderBase struct {
Name string `json:"name"`
ID *string `json:"id"`
Type string `json:"type"`
}
type AuthProviderMetadata interface {
ProviderName() string
ProviderID() *string
ProviderType() string
}
func (bp *AuthProviderBase) ProviderName() string { return bp.Name }
func (bp *AuthProviderBase) ProviderID() *string { return bp.ID }
func (bp *AuthProviderBase) ProviderType() string { return bp.Type }
func (bp *AuthProviderBase) ProviderBase() AuthProviderBase { return *bp }
type FlowSchemaItem struct {
Type string `json:"type"`
Name string `json:"name"`
Required bool `json:"required"`
}