2022-11-12 15:56:17 -05:00
|
|
|
package provider
|
|
|
|
|
2022-11-12 16:31:26 -05:00
|
|
|
import (
|
2022-11-12 17:31:03 -05:00
|
|
|
"net/http"
|
|
|
|
|
2022-11-12 16:31:26 -05:00
|
|
|
"dynatron.me/x/blasphem/pkg/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Constructor func(storage.Store) (AuthProvider, error)
|
|
|
|
|
|
|
|
var Providers = make(map[string]Constructor)
|
|
|
|
|
2022-11-12 15:56:17 -05:00
|
|
|
type AuthProvider interface { // TODO: this should include stepping
|
|
|
|
AuthProviderMetadata
|
|
|
|
ProviderBase() AuthProviderBase
|
|
|
|
FlowSchema() []FlowSchemaItem
|
|
|
|
NewCredData() interface{}
|
2022-11-12 17:31:03 -05:00
|
|
|
ValidateCreds(r *http.Request, reqMap map[string]interface{}) (user ProviderUser, success bool)
|
2022-11-13 19:06:53 -05:00
|
|
|
Lookup(ProviderUser) ProviderUser
|
2022-11-12 15:56:17 -05:00
|
|
|
}
|
|
|
|
|
2022-11-12 16:31:26 -05:00
|
|
|
func Register(providerName string, f func(storage.Store) (AuthProvider, error)) {
|
|
|
|
Providers[providerName] = f
|
|
|
|
}
|
|
|
|
|
2022-11-12 15:56:17 -05:00
|
|
|
type ProviderUser interface {
|
2022-11-13 19:06:53 -05:00
|
|
|
// TODO: make sure this is sane with all the ProviderUser and UserData type stuf
|
2022-11-13 11:55:10 -05:00
|
|
|
UserData() ProviderUser
|
2022-11-12 15:56:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|