Skip to content

Commit a486ada

Browse files
authored
feat: log sb-auth-user-id, sb-auth-session-id, ... on sign in not just refresh token (#2342)
In #2216 some new headers were added to responses that are able to track the user ID, session and other data which cannot be extracted from JWTs. This aids in debugging and correlation of all requests made by a specific user.
1 parent 61ef4db commit a486ada

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

internal/api/anonymous.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (a *API) SignupAnonymously(w http.ResponseWriter, r *http.Request) error {
4444
if terr != nil {
4545
return terr
4646
}
47-
token, terr = a.issueRefreshToken(r, tx, newUser, models.Anonymous, grantParams)
47+
token, terr = a.issueRefreshToken(r, w.Header(), tx, newUser, models.Anonymous, grantParams)
4848
if terr != nil {
4949
return terr
5050
}

internal/api/external.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (a *API) internalExternalProviderCallback(w http.ResponseWriter, r *http.Re
257257
terr = tx.Update(flowState)
258258
} else {
259259
// Implicit flow: issue tokens directly
260-
token, terr = a.issueRefreshToken(r, tx, user, models.OAuth, grantParams)
260+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.OAuth, grantParams)
261261
if terr == nil && flowState != nil {
262262
terr = tx.Destroy(flowState)
263263
}

internal/api/samlacs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (a *API) handleSamlAcs(w http.ResponseWriter, r *http.Request) error {
320320
}
321321
}
322322

323-
token, terr = a.issueRefreshToken(r, tx, user, models.SSOSAML, grantParams)
323+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.SSOSAML, grantParams)
324324

325325
if terr != nil {
326326
return apierrors.NewInternalServerError("Unable to issue refresh token from SAML Assertion").WithInternalError(terr)

internal/api/signup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (a *API) Signup(w http.ResponseWriter, r *http.Request) error {
312312
}); terr != nil {
313313
return terr
314314
}
315-
token, terr = a.issueRefreshToken(r, tx, user, models.PasswordGrant, grantParams)
315+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.PasswordGrant, grantParams)
316316

317317
if terr != nil {
318318
return terr

internal/api/token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
295295
})
296296
}
297297

298-
func (a *API) issueRefreshToken(r *http.Request, conn *storage.Connection, user *models.User, authenticationMethod models.AuthenticationMethod, grantParams models.GrantParams) (*tokens.AccessTokenResponse, error) {
299-
return a.tokenService.IssueRefreshToken(r, make(http.Header), conn, user, authenticationMethod, grantParams)
298+
func (a *API) issueRefreshToken(r *http.Request, headers http.Header, conn *storage.Connection, user *models.User, authenticationMethod models.AuthenticationMethod, grantParams models.GrantParams) (*tokens.AccessTokenResponse, error) {
299+
return a.tokenService.IssueRefreshToken(r, headers, conn, user, authenticationMethod, grantParams)
300300
}
301301

302302
func (a *API) updateMFASessionAndClaims(r *http.Request, tx *storage.Connection, user *models.User, authenticationMethod models.AuthenticationMethod, grantParams models.GrantParams) (*tokens.AccessTokenResponse, error) {

internal/api/token_oidc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (a *API) IdTokenGrant(ctx context.Context, w http.ResponseWriter, r *http.R
306306
return terr
307307
}
308308

309-
token, terr = a.issueRefreshToken(r, tx, user, models.OAuth, grantParams)
309+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.OAuth, grantParams)
310310
if terr != nil {
311311
return terr
312312
}

internal/api/verify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (a *API) verifyGet(w http.ResponseWriter, r *http.Request, params *VerifyPa
182182
}
183183

184184
if isImplicitFlow(flowType) {
185-
token, terr = a.issueRefreshToken(r, tx, user, models.OTP, grantParams)
185+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.OTP, grantParams)
186186
if terr != nil {
187187
return terr
188188
}
@@ -282,7 +282,7 @@ func (a *API) verifyPost(w http.ResponseWriter, r *http.Request, params *VerifyP
282282
if terr := tx.Reload(user); terr != nil {
283283
return terr
284284
}
285-
token, terr = a.issueRefreshToken(r, tx, user, models.OTP, grantParams)
285+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.OTP, grantParams)
286286
if terr != nil {
287287
return terr
288288
}

internal/api/web3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (a *API) web3GrantSolana(ctx context.Context, w http.ResponseWriter, r *htt
165165
return terr
166166
}
167167

168-
token, terr = a.issueRefreshToken(r, tx, user, models.Web3, grantParams)
168+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.Web3, grantParams)
169169
if terr != nil {
170170
return terr
171171
}
@@ -311,7 +311,7 @@ func (a *API) web3GrantEthereum(ctx context.Context, w http.ResponseWriter, r *h
311311
return terr
312312
}
313313

314-
token, terr = a.issueRefreshToken(r, tx, user, models.Web3, grantParams)
314+
token, terr = a.issueRefreshToken(r, w.Header(), tx, user, models.Web3, grantParams)
315315
if terr != nil {
316316
return terr
317317
}

0 commit comments

Comments
 (0)