28 lines
575 B
Go
28 lines
575 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"gitea.teamortix.com/team-ortix/coverage/db"
|
|
)
|
|
|
|
func handleRedirect(w http.ResponseWriter, r *http.Request) {
|
|
params := r.URL.Query()
|
|
code := params.Get("code")
|
|
state := params.Get("state")
|
|
|
|
jwtToken, redirect, err := db.ConsumeOAuthCode(code, state)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: cookieName,
|
|
Value: jwtToken,
|
|
Expires: time.Now().Add(time.Hour * 24 * 7),
|
|
})
|
|
http.Redirect(w, r, redirect, http.StatusTemporaryRedirect)
|
|
}
|