75 lines
3.0 KiB
Go
75 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type OAuthClient struct {
|
|
ID uuid.UUID `db:"id" json:"id"`
|
|
ClientID string `db:"client_id" json:"client_id"`
|
|
ClientSecret string `db:"client_secret" json:"-"`
|
|
Name string `db:"name" json:"name"`
|
|
RedirectURIs json.RawMessage `db:"redirect_uris" json:"redirect_uris"`
|
|
GrantTypes json.RawMessage `db:"grant_types" json:"grant_types"`
|
|
Scopes json.RawMessage `db:"scopes" json:"scopes,omitempty"`
|
|
IsActive bool `db:"is_active" json:"is_active"`
|
|
Trusted bool `db:"trusted" json:"trusted"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
type RefreshTokenRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
TokenHash string `db:"token_hash"`
|
|
UserID uuid.UUID `db:"user_id"`
|
|
ClientID uuid.UUID `db:"client_id"`
|
|
Scopes json.RawMessage `db:"scopes"`
|
|
ExpiresAt time.Time `db:"expires_at"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
}
|
|
|
|
type AuthorizationCodeRow struct {
|
|
ID uuid.UUID `db:"id"`
|
|
CodeHash string `db:"code_hash"`
|
|
UserID uuid.UUID `db:"user_id"`
|
|
ClientID uuid.UUID `db:"client_id"`
|
|
RedirectURI string `db:"redirect_uri"`
|
|
Scopes json.RawMessage `db:"scopes"`
|
|
CodeChallenge string `db:"code_challenge"`
|
|
CodeChallengeMethod string `db:"code_challenge_method"`
|
|
ExpiresAt time.Time `db:"expires_at"`
|
|
ConsumedAt *time.Time `db:"consumed_at"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
}
|
|
|
|
type ClientCreateInput struct {
|
|
Name string `json:"name" binding:"required,min=2,max=128"`
|
|
RedirectURIs []string `json:"redirect_uris" binding:"required,min=1,dive,url"`
|
|
GrantTypes []string `json:"grant_types" binding:"required,min=1,dive,oneof=authorization_code refresh_token"`
|
|
Scopes []string `json:"scopes" binding:"required,min=1,dive,min=1"`
|
|
}
|
|
|
|
type ClientUpdateInput struct {
|
|
Name *string `json:"name" binding:"omitempty,min=2,max=128"`
|
|
RedirectURIs *[]string `json:"redirect_uris" binding:"omitempty,min=1,dive,url"`
|
|
GrantTypes *[]string `json:"grant_types" binding:"omitempty,min=1,dive,oneof=authorization_code refresh_token"`
|
|
Scopes *[]string `json:"scopes" binding:"omitempty,min=1,dive,min=1"`
|
|
Trusted *bool `json:"trusted"`
|
|
IsActive *bool `json:"is_active"`
|
|
}
|
|
|
|
type UserConsent struct {
|
|
ID uuid.UUID `json:"id"`
|
|
UserID uuid.UUID `json:"-"`
|
|
ClientID uuid.UUID `json:"-"`
|
|
ClientIdentifier string `json:"client_id"`
|
|
ClientName string `json:"client_name"`
|
|
Scopes []string `json:"scopes"`
|
|
AuthorizedAt time.Time `json:"authorized_at"`
|
|
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
|
|
RevokedAt *time.Time `json:"revoked_at,omitempty"`
|
|
}
|