mirror of https://github.com/usememos/memos
parent
4ed9a3a0ea
commit
b34aded376
@ -1,58 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
type IdentityProviderType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
IdentityProviderOAuth2 IdentityProviderType = "OAUTH2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IdentityProviderConfig struct {
|
|
||||||
OAuth2Config *IdentityProviderOAuth2Config `json:"oauth2Config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProviderOAuth2Config struct {
|
|
||||||
ClientID string `json:"clientId"`
|
|
||||||
ClientSecret string `json:"clientSecret"`
|
|
||||||
AuthURL string `json:"authUrl"`
|
|
||||||
TokenURL string `json:"tokenUrl"`
|
|
||||||
UserInfoURL string `json:"userInfoUrl"`
|
|
||||||
Scopes []string `json:"scopes"`
|
|
||||||
FieldMapping *FieldMapping `json:"fieldMapping"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FieldMapping struct {
|
|
||||||
Identifier string `json:"identifier"`
|
|
||||||
DisplayName string `json:"displayName"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProvider struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Type IdentityProviderType `json:"type"`
|
|
||||||
IdentifierFilter string `json:"identifierFilter"`
|
|
||||||
Config *IdentityProviderConfig `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProviderCreate struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Type IdentityProviderType `json:"type"`
|
|
||||||
IdentifierFilter string `json:"identifierFilter"`
|
|
||||||
Config *IdentityProviderConfig `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProviderFind struct {
|
|
||||||
ID *int
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProviderPatch struct {
|
|
||||||
ID int
|
|
||||||
Type IdentityProviderType `json:"type"`
|
|
||||||
Name *string `json:"name"`
|
|
||||||
IdentifierFilter *string `json:"identifierFilter"`
|
|
||||||
Config *IdentityProviderConfig `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type IdentityProviderDelete struct {
|
|
||||||
ID int
|
|
||||||
}
|
|
@ -0,0 +1,24 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
// UnknownID is the ID for unknowns.
|
||||||
|
const UnknownID = -1
|
||||||
|
|
||||||
|
// RowStatus is the status for a row.
|
||||||
|
type RowStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Normal is the status for a normal row.
|
||||||
|
Normal RowStatus = "NORMAL"
|
||||||
|
// Archived is the status for an archived row.
|
||||||
|
Archived RowStatus = "ARCHIVED"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e RowStatus) String() string {
|
||||||
|
switch e {
|
||||||
|
case Normal:
|
||||||
|
return "NORMAL"
|
||||||
|
case Archived:
|
||||||
|
return "ARCHIVED"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package v1
|
||||||
|
|
||||||
|
// Role is the type of a role.
|
||||||
|
type Role string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Host is the HOST role.
|
||||||
|
Host Role = "HOST"
|
||||||
|
// Admin is the ADMIN role.
|
||||||
|
Admin Role = "ADMIN"
|
||||||
|
// NormalUser is the USER role.
|
||||||
|
NormalUser Role = "USER"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e Role) String() string {
|
||||||
|
switch e {
|
||||||
|
case Host:
|
||||||
|
return "HOST"
|
||||||
|
case Admin:
|
||||||
|
return "ADMIN"
|
||||||
|
case NormalUser:
|
||||||
|
return "USER"
|
||||||
|
}
|
||||||
|
return "USER"
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package teststore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIdentityProviderStore(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
ts := NewTestingStore(ctx, t)
|
||||||
|
createdIDP, err := ts.CreateIdentityProvider(ctx, &store.IdentityProviderMessage{
|
||||||
|
Name: "GitHub OAuth",
|
||||||
|
Type: store.IdentityProviderOAuth2,
|
||||||
|
IdentifierFilter: "",
|
||||||
|
Config: &store.IdentityProviderConfig{
|
||||||
|
OAuth2Config: &store.IdentityProviderOAuth2Config{
|
||||||
|
ClientID: "asd",
|
||||||
|
ClientSecret: "123",
|
||||||
|
AuthURL: "https://github.com/auth",
|
||||||
|
TokenURL: "https://github.com/token",
|
||||||
|
UserInfoURL: "https://github.com/user",
|
||||||
|
Scopes: []string{"login"},
|
||||||
|
FieldMapping: &store.FieldMapping{
|
||||||
|
Identifier: "login",
|
||||||
|
DisplayName: "name",
|
||||||
|
Email: "emai",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
idp, err := ts.GetIdentityProvider(ctx, &store.FindIdentityProviderMessage{
|
||||||
|
ID: &createdIDP.ID,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, createdIDP, idp)
|
||||||
|
err = ts.DeleteIdentityProvider(ctx, &store.DeleteIdentityProviderMessage{
|
||||||
|
ID: idp.ID,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
idpList, err := ts.ListIdentityProviders(ctx, &store.FindIdentityProviderMessage{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 0, len(idpList))
|
||||||
|
}
|
Loading…
Reference in New Issue