Handle next parameters even through OIDC

This commit is contained in:
nemunaire 2022-05-15 12:36:17 +02:00
parent 22df36c814
commit 4872a74155
1 changed files with 15 additions and 1 deletions

View File

@ -20,6 +20,7 @@ var (
oidcRedirectURL = "https://srs.nemunai.re"
oauth2Config oauth2.Config
oidcVerifier *oidc.IDTokenVerifier
nextSessionMap = map[string]string{}
)
func init() {
@ -60,6 +61,12 @@ func initializeOIDC() {
func redirectOIDC_CRI(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
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 {
http.Error(w, fmt.Sprintf("{'errmsg':%q}", err.Error()), http.StatusInternalServerError)
} else {
@ -121,5 +128,12 @@ func OIDC_CRI_complete(w http.ResponseWriter, r *http.Request, ps httprouter.Par
return
}
http.Redirect(w, r, "/", http.StatusFound)
// 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)
}
}