OAuth2 Support

This commit is contained in:
2024-01-30 15:57:49 +08:00
parent f78ccd8d9d
commit 0497e9717b
15 changed files with 442 additions and 47 deletions

View File

@ -17,17 +17,18 @@ const (
type Account struct {
BaseModel
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
State AccountState `json:"state"`
Profile AccountProfile `json:"profile"`
Session []AuthSession `json:"sessions"`
Challenges []AuthChallenge `json:"challenges"`
Factors []AuthFactor `json:"factors"`
Contacts []AccountContact `json:"contacts"`
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
ConfirmedAt *time.Time `json:"confirmed_at"`
Permissions datatypes.JSONType[[]string] `json:"permissions"`
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
State AccountState `json:"state"`
Profile AccountProfile `json:"profile"`
Sessions []AuthSession `json:"sessions"`
Challenges []AuthChallenge `json:"challenges"`
Factors []AuthFactor `json:"factors"`
Contacts []AccountContact `json:"contacts"`
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
ThirdClients []ThirdClient `json:"clients"`
ConfirmedAt *time.Time `json:"confirmed_at"`
Permissions datatypes.JSONType[[]string] `json:"permissions"`
}
func (v Account) GetPrimaryEmail() AccountContact {

View File

@ -27,6 +27,7 @@ type AuthSession struct {
BaseModel
Claims datatypes.JSONSlice[string] `json:"claims"`
Audiences datatypes.JSONSlice[string] `json:"audiences"`
Challenge AuthChallenge `json:"challenge" gorm:"foreignKey:SessionID"`
GrantToken string `json:"grant_token"`
AccessToken string `json:"access_token"`
@ -34,6 +35,7 @@ type AuthSession struct {
ExpiredAt *time.Time `json:"expired_at"`
AvailableAt *time.Time `json:"available_at"`
LastGrantAt *time.Time `json:"last_grant_at"`
ClientID *uint `json:"client_id"`
AccountID uint `json:"account_id"`
}
@ -59,6 +61,7 @@ const (
type AuthChallenge struct {
BaseModel
Location string `json:"location"`
IpAddress string `json:"ip_address"`
UserAgent string `json:"user_agent"`
RiskLevel int `json:"risk_level"`

View File

@ -1,4 +1,17 @@
package models
type OauthClients struct {
import "gorm.io/datatypes"
type ThirdClient struct {
BaseModel
Alias string `json:"alias" gorm:"uniqueIndex"`
Name string `json:"name"`
Description string `json:"description"`
Secret string `json:"secret"`
Urls datatypes.JSONSlice[string] `json:"urls"`
Callbacks datatypes.JSONSlice[string] `json:"callbacks"`
Sessions []AuthSession `json:"sessions" gorm:"foreignKey:ClientID"`
IsDraft bool `json:"is_draft"`
AccountID *uint `json:"account_id"`
}