mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.4 KiB
Go
73 lines
2.4 KiB
Go
|
1 week ago
|
//
|
||
|
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
||
|
|
// 2025-03-04 16:08:06
|
||
|
|
// Distributed under terms of the MIT license.
|
||
|
|
//
|
||
|
|
|
||
|
|
package models
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// OAuthClient OAuth2.0 客户端
|
||
|
|
type OAuthClient struct {
|
||
|
|
Base
|
||
|
|
ClientID string `json:"client_id" gorm:"uniqueIndex;size:100;not null"`
|
||
|
|
ClientSecret string `json:"-" gorm:"size:255;not null"`
|
||
|
|
Name string `json:"name" gorm:"size:100;not null"`
|
||
|
|
Description string `json:"description" gorm:"size:500"`
|
||
|
|
RedirectURIs string `json:"redirect_uris" gorm:"type:text"` // JSON数组
|
||
|
|
AllowedScopes string `json:"allowed_scopes" gorm:"size:500"` // 空格分隔
|
||
|
|
OwnerID string `json:"owner_id" gorm:"not null"`
|
||
|
|
OrgID string `json:"org_id" gorm:"index"`
|
||
|
|
Status int `json:"status" gorm:"default:1"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (OAuthClient) TableName() string {
|
||
|
|
return "oauth_clients"
|
||
|
|
}
|
||
|
|
|
||
|
|
// OAuthAuthorizationCode OAuth2.0 授权码
|
||
|
|
type OAuthAuthorizationCode struct {
|
||
|
|
Base
|
||
|
|
Code string `json:"code" gorm:"uniqueIndex;size:100;not null"`
|
||
|
|
ClientID string `json:"client_id" gorm:"index;not null"`
|
||
|
|
UserID string `json:"user_id" gorm:"index;not null"`
|
||
|
|
OrgID string `json:"org_id" gorm:"index"`
|
||
|
|
RedirectURI string `json:"redirect_uri" gorm:"size:500"`
|
||
|
|
Scope string `json:"scope" gorm:"size:200"`
|
||
|
|
CodeChallenge string `json:"-" gorm:"size:128"`
|
||
|
|
CodeChallengeMethod string `json:"-" gorm:"size:10"`
|
||
|
|
ExpiresAt time.Time `json:"expires_at"`
|
||
|
|
Used bool `json:"used" gorm:"default:false"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (OAuthAuthorizationCode) TableName() string {
|
||
|
|
return "oauth_authorization_codes"
|
||
|
|
}
|
||
|
|
|
||
|
|
// OAuthToken OAuth2.0 令牌
|
||
|
|
type OAuthToken struct {
|
||
|
|
Base
|
||
|
|
ClientID string `json:"client_id" gorm:"index;not null"`
|
||
|
|
UserID string `json:"user_id" gorm:"index;not null"`
|
||
|
|
OrgID string `json:"org_id" gorm:"index"`
|
||
|
|
AccessToken string `json:"-" gorm:"uniqueIndex;size:255;not null"`
|
||
|
|
RefreshToken string `json:"-" gorm:"uniqueIndex;size:255"`
|
||
|
|
TokenType string `json:"token_type" gorm:"size:20;default:'Bearer'"`
|
||
|
|
Scope string `json:"scope" gorm:"size:200"`
|
||
|
|
ExpiresAt time.Time `json:"expires_at"`
|
||
|
|
Revoked bool `json:"revoked" gorm:"default:false"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (OAuthToken) TableName() string {
|
||
|
|
return "oauth_tokens"
|
||
|
|
}
|
||
|
|
|
||
|
|
// OAuthClientStatus 客户端状态
|
||
|
|
const (
|
||
|
|
OAuthClientStatusDisabled = 0
|
||
|
|
OAuthClientStatusActive = 1
|
||
|
|
)
|