re-construct oauth

This commit is contained in:
Tao Chen
2024-11-02 04:01:28 +08:00
parent c5e3482538
commit 485ae54e9e
14 changed files with 491 additions and 491 deletions

View File

@@ -1,6 +1,9 @@
package admin
import "Gwen/model"
import (
"Gwen/model"
"strings"
)
type BindOauthForm struct {
Op string `json:"op" binding:"required"`
@@ -13,19 +16,37 @@ type UnBindOauthForm struct {
Op string `json:"op" binding:"required"`
}
type OauthForm struct {
Id uint `json:"id"`
Op string `json:"op" validate:"required"`
Issuer string `json:"issuer" validate:"omitempty,url"`
Scopes string `json:"scopes" validate:"omitempty"`
ClientId string `json:"client_id" validate:"required"`
ClientSecret string `json:"client_secret" validate:"required"`
RedirectUrl string `json:"redirect_url" validate:"required"`
AutoRegister *bool `json:"auto_register"`
Id uint `json:"id"`
Op string `json:"op" validate:"omitempty"`
OauthType string `json:"oauth_type" validate:"required"`
Issuer string `json:"issuer" validate:"omitempty,url"`
Scopes string `json:"scopes" validate:"omitempty"`
ClientId string `json:"client_id" validate:"required"`
ClientSecret string `json:"client_secret" validate:"required"`
RedirectUrl string `json:"redirect_url" validate:"required"`
AutoRegister *bool `json:"auto_register"`
}
func (of *OauthForm) ToOauth() *model.Oauth {
op := strings.ToLower(of.Op)
op = strings.TrimSpace(op)
if op == "" {
switch of.OauthType {
case model.OauthTypeGithub:
of.Op = "GitHub"
case model.OauthTypeGoogle:
of.Op = "Google"
case model.OauthTypeOidc:
of.Op = "OIDC"
case model.OauthTypeWebauth:
of.Op = "WebAuth"
default:
of.Op = of.OauthType
}
}
oa := &model.Oauth{
Op: of.Op,
OauthType: of.OauthType,
ClientId: of.ClientId,
ClientSecret: of.ClientSecret,
RedirectUrl: of.RedirectUrl,