|
|
@@ -180,14 +180,12 @@ func (os *OauthService) GetOauthConfig(c *gin.Context, op string) (err error, oa
|
|
180
|
180
|
if oauthInfo.Id == 0 || oauthInfo.ClientId == "" || oauthInfo.ClientSecret == "" {
|
|
181
|
181
|
return errors.New("ConfigNotFound"), nil, nil, nil
|
|
182
|
182
|
}
|
|
183
|
|
- host := c.GetHeader("Origin")
|
|
184
|
|
- if host == "" {
|
|
185
|
|
- host = Config.Rustdesk.ApiServer
|
|
186
|
|
- }
|
|
|
183
|
+ redirectUrl := os.buildRedirectURL(c)
|
|
|
184
|
+ Logger.Debug("Redirect URL: ", redirectUrl)
|
|
187
|
185
|
oauthConfig = &oauth2.Config{
|
|
188
|
186
|
ClientID: oauthInfo.ClientId,
|
|
189
|
187
|
ClientSecret: oauthInfo.ClientSecret,
|
|
190
|
|
- RedirectURL: host + "/api/oidc/callback",
|
|
|
188
|
+ RedirectURL: redirectUrl,
|
|
191
|
189
|
}
|
|
192
|
190
|
|
|
193
|
191
|
// Maybe should validate the oauthConfig here
|
|
|
@@ -529,3 +527,22 @@ func (os *OauthService) getGithubPrimaryEmail(client *http.Client, githubUser *m
|
|
529
|
527
|
|
|
530
|
528
|
return fmt.Errorf("no primary verified email found")
|
|
531
|
529
|
}
|
|
|
530
|
+
|
|
|
531
|
+func (os *OauthService) buildRedirectURL(c *gin.Context) string {
|
|
|
532
|
+ baseUrl := Config.Rustdesk.ApiServer
|
|
|
533
|
+ host := c.Request.Host
|
|
|
534
|
+
|
|
|
535
|
+ if host != "" {
|
|
|
536
|
+ scheme := c.GetHeader("X-Forwarded-Proto")
|
|
|
537
|
+ if scheme == "" {
|
|
|
538
|
+ if c.Request.TLS != nil {
|
|
|
539
|
+ scheme = "https"
|
|
|
540
|
+ } else {
|
|
|
541
|
+ scheme = "http"
|
|
|
542
|
+ }
|
|
|
543
|
+ }
|
|
|
544
|
+ baseUrl = fmt.Sprintf("%s://%s", scheme, host)
|
|
|
545
|
+ }
|
|
|
546
|
+
|
|
|
547
|
+ return fmt.Sprintf("%s/api/oidc/callback", baseUrl)
|
|
|
548
|
+}
|