Skip to content

Commit

Permalink
Fix base URI not included in generated OpenID Connect URLs (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoffatt committed Jul 18, 2024
1 parent fef54a1 commit 1e388d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ func oidcLogin(w http.ResponseWriter, r *http.Request) {
_, oauth, err := getOidcProvider(pid, ctx, redirectPath)
if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
loginURL, _ := url.JoinPath(util.Config.WebHost, "auth/login")
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}
state := generateStateOauthCookie(w)
Expand Down Expand Up @@ -570,14 +571,16 @@ func getSecretFromFile(source string) (string, error) {
func oidcRedirect(w http.ResponseWriter, r *http.Request) {
pid := mux.Vars(r)["provider"]
oauthState, err := r.Cookie("oauthstate")
loginURL, _ := url.JoinPath(util.Config.WebHost, "auth/login")

if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

if r.FormValue("state") != oauthState.Value {
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

Expand All @@ -586,14 +589,14 @@ func oidcRedirect(w http.ResponseWriter, r *http.Request) {
_oidc, oauth, err := getOidcProvider(pid, ctx, r.URL.Path)
if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

provider, ok := util.Config.OidcProviders[pid]
if !ok {
log.Error(fmt.Errorf("no such provider: %s", pid))
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

Expand All @@ -604,7 +607,7 @@ func oidcRedirect(w http.ResponseWriter, r *http.Request) {
oauth2Token, err := oauth.Exchange(ctx, code)
if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

Expand Down Expand Up @@ -643,7 +646,7 @@ func oidcRedirect(w http.ResponseWriter, r *http.Request) {

if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

Expand All @@ -658,20 +661,20 @@ func oidcRedirect(w http.ResponseWriter, r *http.Request) {
user, err = helpers.Store(r).CreateUserWithoutPassword(user)
if err != nil {
log.Error(err.Error())
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}
}

if !user.External {
log.Error(fmt.Errorf("OIDC user '%s' conflicts with local user", user.Username))
http.Redirect(w, r, "/auth/login", http.StatusTemporaryRedirect)
http.Redirect(w, r, loginURL, http.StatusTemporaryRedirect)
return
}

createSession(w, r, user)

redirectPath := mux.Vars(r)["redirect_path"]

http.Redirect(w, r, "/"+redirectPath, http.StatusTemporaryRedirect)
http.Redirect(w, r, util.Config.WebHost+redirectPath, http.StatusTemporaryRedirect)
}
2 changes: 1 addition & 1 deletion web/src/views/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default {
},
async oidcSignIn(provider) {
document.location = `/api/auth/oidc/${provider}/login${window.location.search}`;
document.location = `${document.baseURI}api/auth/oidc/${provider}/login`;
},
},
};
Expand Down

0 comments on commit 1e388d1

Please sign in to comment.