sessions #2

Merged
admin merged 63 commits from sessions into main 2025-06-16 19:03:01 +02:00
52 changed files with 2621 additions and 190 deletions
Showing only changes of commit 0db54e0268 - Show all commits

View File

@ -269,6 +269,26 @@ func (h *OAuthHandler) tokenEndpoint(w http.ResponseWriter, r *http.Request) {
return return
} }
refreshJTI, err := uuid.Parse(claims.ID)
if err != nil {
log.Printf("ERR: Failed to parse refresh token JTI as uuid: %v\n", err)
web.Error(w, "failed to refresh token", http.StatusInternalServerError)
return
}
session, err := h.repo.GetServiceSessionByRefreshJTI(r.Context(), &refreshJTI)
if err != nil {
log.Printf("ERR: Failed to find session by '%s' refresh jti: %v\n", refreshJTI.String(), err)
web.Error(w, "session invalid", http.StatusUnauthorized)
return
}
if !session.IsActive {
log.Printf("INFO: Session with id '%s' is not active", session.ID.String())
web.Error(w, "session ended", http.StatusUnauthorized)
return
}
userID, err := uuid.Parse(claims.UserID) userID, err := uuid.Parse(claims.UserID)
if err != nil { if err != nil {
web.Error(w, "invalid user credentials in refresh token", http.StatusBadRequest) web.Error(w, "invalid user credentials in refresh token", http.StatusBadRequest)
@ -284,6 +304,17 @@ func (h *OAuthHandler) tokenEndpoint(w http.ResponseWriter, r *http.Request) {
id, access, refresh, err := h.signApiTokens(&user, &apiService, nil) id, access, refresh, err := h.signApiTokens(&user, &apiService, nil)
if err := h.repo.UpdateServiceSessionTokens(r.Context(), repository.UpdateServiceSessionTokensParams{
ID: session.ID,
AccessTokenID: &access.ID,
RefreshTokenID: &refresh.ID,
ExpiresAt: &refresh.ExpiresAt,
}); err != nil {
log.Printf("ERR: Failed to update service session with '%s' id: %v\n", session.ID.String(), err)
web.Error(w, "failed to update session", http.StatusInternalServerError)
return
}
type Response struct { type Response struct {
IdToken string `json:"id_token"` IdToken string `json:"id_token"`
TokenType string `json:"token_type"` TokenType string `json:"token_type"`