mirror of
https://github.com/usememos/memos.git
synced 2026-01-06 08:24:32 +08:00
feat(api): update interceptor to handle AccessTokenV2 and PAT
- Update WrapUnary to check AuthResult.Claims for stateless access tokens - Set UserClaims in context when authenticated via Access Token V2 - Set UserID in context for both stateless and stateful auth paths - Handle PAT authentication through existing SetUserInContext path - Maintain backward compatibility with legacy session/JWT auth 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7444ce9f32
commit
1df489de0e
1 changed files with 9 additions and 2 deletions
|
|
@ -198,9 +198,16 @@ func (in *AuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
|
|||
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("authentication required"))
|
||||
}
|
||||
|
||||
// Set user in context (may be nil for public endpoints)
|
||||
// Set context based on auth result
|
||||
if result != nil {
|
||||
ctx = auth.SetUserInContext(ctx, result.User, result.SessionID, result.AccessToken)
|
||||
if result.Claims != nil {
|
||||
// Access Token V2 - stateless, use claims
|
||||
ctx = auth.SetUserClaimsInContext(ctx, result.Claims)
|
||||
ctx = context.WithValue(ctx, auth.UserIDContextKey, result.Claims.UserID)
|
||||
} else if result.User != nil {
|
||||
// PAT or legacy auth - have full user
|
||||
ctx = auth.SetUserInContext(ctx, result.User, result.SessionID, result.AccessToken)
|
||||
}
|
||||
}
|
||||
|
||||
return next(ctx, req)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue