store oauth 2.0 user info in token context instead of being passed through frontend parameters

This commit is contained in:
MaysWind
2025-10-21 23:49:18 +08:00
parent 13ada3575a
commit 46e275d843
31 changed files with 174 additions and 83 deletions
+17
View File
@@ -13,6 +13,7 @@ import (
const webContextRequestIdFieldKey = "REQUEST_ID"
const webContextTextualTokenFieldKey = "TOKEN_STRING"
const webContextTokenClaimsFieldKey = "TOKEN_CLAIMS"
const webContextTokenContextFieldKey = "TOKEN_CONTEXT"
const webContextResponseErrorFieldKey = "RESPONSE_ERROR"
// AcceptLanguageHeaderName represents the header name of accept language
@@ -113,6 +114,22 @@ func (c *WebContext) GetTokenClaims() *UserTokenClaims {
return claims.(*UserTokenClaims)
}
// SetTokenContext sets the given user token context to context
func (c *WebContext) SetTokenContext(context string) {
c.Set(webContextTokenContextFieldKey, context)
}
// GetTokenContext returns the current user token context
func (c *WebContext) GetTokenContext() string {
context, exists := c.Get(webContextTokenContextFieldKey)
if !exists {
return ""
}
return context.(string)
}
// GetCurrentUid returns the current user uid by the current user token
func (c *WebContext) GetCurrentUid() int64 {
claims := c.GetTokenClaims()