mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2026-02-17 14:04:51 +08:00
feat: Optimize login workflow (#345)
* add "disable_pwd" and "auto_oidc" at /admin/login-options * fix: build RedirectURL by host and scheme, not Origin
This commit is contained in:
@@ -169,6 +169,8 @@ func (ct *Login) LoginOptions(c *gin.Context) {
|
|||||||
"ops": ops,
|
"ops": ops,
|
||||||
"register": global.Config.App.Register,
|
"register": global.Config.App.Register,
|
||||||
"need_captcha": needCaptcha,
|
"need_captcha": needCaptcha,
|
||||||
|
"disable_pwd": global.Config.App.DisablePwdLogin,
|
||||||
|
"auto_oidc": global.Config.App.DisablePwdLogin && len(ops) == 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,14 +180,12 @@ func (os *OauthService) GetOauthConfig(c *gin.Context, op string) (err error, oa
|
|||||||
if oauthInfo.Id == 0 || oauthInfo.ClientId == "" || oauthInfo.ClientSecret == "" {
|
if oauthInfo.Id == 0 || oauthInfo.ClientId == "" || oauthInfo.ClientSecret == "" {
|
||||||
return errors.New("ConfigNotFound"), nil, nil, nil
|
return errors.New("ConfigNotFound"), nil, nil, nil
|
||||||
}
|
}
|
||||||
host := c.GetHeader("Origin")
|
redirectUrl := os.buildRedirectURL(c)
|
||||||
if host == "" {
|
Logger.Debug("Redirect URL: ", redirectUrl)
|
||||||
host = Config.Rustdesk.ApiServer
|
|
||||||
}
|
|
||||||
oauthConfig = &oauth2.Config{
|
oauthConfig = &oauth2.Config{
|
||||||
ClientID: oauthInfo.ClientId,
|
ClientID: oauthInfo.ClientId,
|
||||||
ClientSecret: oauthInfo.ClientSecret,
|
ClientSecret: oauthInfo.ClientSecret,
|
||||||
RedirectURL: host + "/api/oidc/callback",
|
RedirectURL: redirectUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maybe should validate the oauthConfig here
|
// Maybe should validate the oauthConfig here
|
||||||
@@ -529,3 +527,22 @@ func (os *OauthService) getGithubPrimaryEmail(client *http.Client, githubUser *m
|
|||||||
|
|
||||||
return fmt.Errorf("no primary verified email found")
|
return fmt.Errorf("no primary verified email found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *OauthService) buildRedirectURL(c *gin.Context) string {
|
||||||
|
baseUrl := Config.Rustdesk.ApiServer
|
||||||
|
host := c.Request.Host
|
||||||
|
|
||||||
|
if host != "" {
|
||||||
|
scheme := c.GetHeader("X-Forwarded-Proto")
|
||||||
|
if scheme == "" {
|
||||||
|
if c.Request.TLS != nil {
|
||||||
|
scheme = "https"
|
||||||
|
} else {
|
||||||
|
scheme = "http"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baseUrl = fmt.Sprintf("%s://%s", scheme, host)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s/api/oidc/callback", baseUrl)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user