This commit is contained in:
Daniel Ponte 2022-11-12 17:42:51 -05:00
parent 25c3e9421f
commit a540f94108
7 changed files with 33 additions and 40 deletions

View file

@ -35,14 +35,14 @@ const (
)
type Flow struct {
Type FlowType `json:"type"`
ID FlowID `json:"flow_id"`
Handler []*string `json:"handler"`
StepID *Step `json:"step_id,omitempty"`
Type FlowType `json:"type"`
ID FlowID `json:"flow_id"`
Handler []*string `json:"handler"`
StepID *Step `json:"step_id,omitempty"`
Schema []provider.FlowSchemaItem `json:"data_schema"`
Errors interface{} `json:"errors"`
DescPlace *string `json:"description_placeholders"`
LastStep *string `json:"last_step"`
Errors interface{} `json:"errors"`
DescPlace *string `json:"description_placeholders"`
LastStep *string `json:"last_step"`
request *FlowRequest
ctime time.Time

View file

@ -39,7 +39,7 @@ func (h *HAUser) ProviderUserData() interface{} { return h.UserData() }
type HomeAssistantProvider struct {
provider.AuthProviderBase `json:"-"`
Users []HAUser `json:"users"`
Users []HAUser `json:"users"`
}
func NewHAProvider(s storage.Store) (provider.AuthProvider, error) {
@ -127,4 +127,3 @@ func (hap *HomeAssistantProvider) FlowSchema() []provider.FlowSchemaItem {
func init() {
provider.Register(HomeAssistant, NewHAProvider)
}

View file

@ -49,5 +49,3 @@ type FlowSchemaItem struct {
Name string `json:"name"`
Required bool `json:"required"`
}

View file

@ -46,7 +46,7 @@ func New(s storage.Store) (provider.AuthProvider, error) {
func (hap *TrustedNetworksProvider) ValidateCreds(r *http.Request, rm map[string]interface{}) (provider.ProviderUser, bool) {
/*
if req.RemoteAddr in allowed then do the thing
if req.RemoteAddr in allowed then do the thing
*/
return nil, false
}
@ -73,4 +73,3 @@ func (hap *TrustedNetworksProvider) FlowSchema() []provider.FlowSchemaItem {
func init() {
provider.Register(TrustedNetworks, New)
}

View file

@ -66,20 +66,20 @@ func (ss *SessionStore) verify(tr *TokenRequest, r *http.Request) (provider.Prov
}
type Credential struct {
ID CredID `json:"id"`
UserID UserID `json:"user_id"`
AuthProviderType string `json:"auth_provider_type"`
AuthProviderID *string `json:"auth_provider_id"`
DataRaw json.RawMessage `json:"data,omitempty"`
user provider.ProviderUser
ID CredID `json:"id"`
UserID UserID `json:"user_id"`
AuthProviderType string `json:"auth_provider_type"`
AuthProviderID *string `json:"auth_provider_id"`
DataRaw json.RawMessage `json:"data,omitempty"`
user provider.ProviderUser
}
func (cred *Credential) MarshalJSON() ([]byte, error) {
rm := map[string]interface{}{
"id": cred.ID,
"user_id": cred.UserID,
"id": cred.ID,
"user_id": cred.UserID,
"auth_provider_type": cred.user.ProviderType(),
"auth_provider_id": cred.user.ProviderID(),
"auth_provider_id": cred.user.ProviderID(),
}
providerData := cred.user.ProviderUserData()
@ -123,7 +123,7 @@ type GrantType string
const (
GTAuthorizationCode GrantType = "authorization_code"
GTRefreshToken GrantType = "refresh_token"
GTRefreshToken GrantType = "refresh_token"
)
type ClientID string
@ -135,8 +135,8 @@ func (c *ClientID) IsValid() bool {
type TokenRequest struct {
ClientID ClientID `form:"client_id"`
Code TokenID `form:"code"`
GrantType GrantType `form:"grant_type"`
Code TokenID `form:"code"`
GrantType GrantType `form:"grant_type"`
}
func (a *Authenticator) TokenHandler(c echo.Context) error {
@ -163,7 +163,7 @@ func (a *Authenticator) TokenHandler(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: "bad user"})
}
if err := user.allowedToAuth(); err != nil {
if err := user.allowedToAuth(); err != nil {
return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: err.Error()})
}
return c.String(http.StatusOK, "token good I guess")

View file

@ -1,8 +1,8 @@
package auth
import (
"fmt"
"encoding/json"
"fmt"
"dynatron.me/x/blasphem/pkg/storage"
)
@ -11,13 +11,12 @@ const (
AuthStoreKey = "auth"
)
type AuthStore interface {
}
type authStore struct {
Users []User `json:"users"`
Groups interface {} `json:"groups"`
Users []User `json:"users"`
Groups interface{} `json:"groups"`
Credentials []Credential `json:"credentials"`
userMap map[UserID]*User

View file

@ -11,18 +11,18 @@ type GroupID string
type CredID string
type User struct {
ID UserID `json:"id"`
GroupIDs []GroupID `json:"group_ids"`
Data interface{} `json:"data,omitempty"`
ID UserID `json:"id"`
GroupIDs []GroupID `json:"group_ids"`
Data interface{} `json:"data,omitempty"`
UserMetadata
}
type UserMetadata struct {
Active bool `json:"is_active"`
Owner bool `json:"is_owner"`
LocalOnly bool `json:"local_only"`
SystemGenerated bool `json:"system_generated"`
Name string `json:"name"`
Active bool `json:"is_active"`
Owner bool `json:"is_owner"`
LocalOnly bool `json:"local_only"`
SystemGenerated bool `json:"system_generated"`
Name string `json:"name"`
}
func (u *User) allowedToAuth() error {
@ -38,5 +38,3 @@ func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
panic("not implemented")
return &User{}, nil
}