mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
store oauth 2.0 user info in token context instead of being passed through frontend parameters
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user