38 lines
926 B
Go
38 lines
926 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (h *Handler) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
|
code := r.URL.Query().Get("code")
|
|
if code == "" {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
session, _ := h.idp.SessionsStore.Get(r, "parcoursmob_session")
|
|
redirectSession := ""
|
|
if session.Values["redirect"] != nil && session.Values["redirect"] != "" {
|
|
redirectSession = session.Values["redirect"].(string)
|
|
delete(session.Values, "redirect")
|
|
}
|
|
|
|
result, err := h.applicationHandler.ProcessOAuth2Callback(code, redirectSession)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
session.Values["idtoken"] = result.IDToken
|
|
|
|
if err = session.Save(r, w); err != nil {
|
|
log.Error().Err(err).Msg("Cannot save session")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, result.RedirectURL, http.StatusFound)
|
|
} |