mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2025-12-02 10:03:16 +00:00
re-construct oauth
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user