Handle next parameters even through OIDC
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-05-15 12:36:17 +02:00
parent a3e1797240
commit 5e20cec59d

View File

@ -20,6 +20,7 @@ var (
oidcRedirectURL = "https://srs.nemunai.re" oidcRedirectURL = "https://srs.nemunai.re"
oauth2Config oauth2.Config oauth2Config oauth2.Config
oidcVerifier *oidc.IDTokenVerifier oidcVerifier *oidc.IDTokenVerifier
nextSessionMap = map[string]string{}
) )
func init() { func init() {
@ -60,6 +61,12 @@ func initializeOIDC() {
func redirectOIDC_CRI(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { func redirectOIDC_CRI(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
session, err := NewSession() session, err := NewSession()
// Save next parameter
if len(r.URL.Query().Get("next")) > 0 {
nextSessionMap[fmt.Sprintf("%x", session.Id)] = r.URL.Query().Get("next")
}
if err != nil { if err != nil {
http.Error(w, fmt.Sprintf("{'errmsg':%q}", err.Error()), http.StatusInternalServerError) http.Error(w, fmt.Sprintf("{'errmsg':%q}", err.Error()), http.StatusInternalServerError)
} else { } else {
@ -121,5 +128,12 @@ func OIDC_CRI_complete(w http.ResponseWriter, r *http.Request, ps httprouter.Par
return return
} }
// Retrieve next URL associated with session
if next, ok := nextSessionMap[fmt.Sprintf("%x", session.Id)]; ok {
http.Redirect(w, r, next, http.StatusFound)
delete(nextSessionMap, fmt.Sprintf("%x", session.Id))
} else {
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
}
} }