mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-13 17:10:36 +00:00
Fixed session_rid in funcspec
This commit is contained in:
parent
1baa0af0ac
commit
4e2fe33b77
@ -758,8 +758,10 @@ func (h *Handler) replaceMetaVariables(sqlquery string, r *http.Request, userCtx
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(sqlquery, "[rid_session]") {
|
if strings.Contains(sqlquery, "[rid_session]") {
|
||||||
sessionID, _ := strconv.ParseInt(userCtx.SessionID, 10, 64)
|
sqlquery = strings.ReplaceAll(sqlquery, "[rid_session]", fmt.Sprintf("%d", userCtx.SessionRID))
|
||||||
sqlquery = strings.ReplaceAll(sqlquery, "[rid_session]", fmt.Sprintf("%d", sessionID))
|
}
|
||||||
|
if strings.Contains(sqlquery, "[id_session]") {
|
||||||
|
sqlquery = strings.ReplaceAll(sqlquery, "[id_session]", userCtx.SessionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(sqlquery, "[method]") {
|
if strings.Contains(sqlquery, "[method]") {
|
||||||
|
|||||||
@ -7,15 +7,16 @@ import (
|
|||||||
|
|
||||||
// UserContext holds authenticated user information
|
// UserContext holds authenticated user information
|
||||||
type UserContext struct {
|
type UserContext struct {
|
||||||
UserID int `json:"user_id"`
|
UserID int `json:"user_id"`
|
||||||
UserName string `json:"user_name"`
|
UserName string `json:"user_name"`
|
||||||
UserLevel int `json:"user_level"`
|
UserLevel int `json:"user_level"`
|
||||||
SessionID string `json:"session_id"`
|
SessionID string `json:"session_id"`
|
||||||
RemoteID string `json:"remote_id"`
|
SessionRID int64 `json:"session_rid"`
|
||||||
Roles []string `json:"roles"`
|
RemoteID string `json:"remote_id"`
|
||||||
Email string `json:"email"`
|
Roles []string `json:"roles"`
|
||||||
Claims map[string]any `json:"claims"`
|
Email string `json:"email"`
|
||||||
Meta map[string]any `json:"meta"` // Additional metadata that can hold any JSON-serializable values
|
Claims map[string]any `json:"claims"`
|
||||||
|
Meta map[string]any `json:"meta"` // Additional metadata that can hold any JSON-serializable values
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginRequest contains credentials for login
|
// LoginRequest contains credentials for login
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package security
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// contextKey is a custom type for context keys to avoid collisions
|
// contextKey is a custom type for context keys to avoid collisions
|
||||||
@ -14,6 +15,7 @@ const (
|
|||||||
UserNameKey contextKey = "user_name"
|
UserNameKey contextKey = "user_name"
|
||||||
UserLevelKey contextKey = "user_level"
|
UserLevelKey contextKey = "user_level"
|
||||||
SessionIDKey contextKey = "session_id"
|
SessionIDKey contextKey = "session_id"
|
||||||
|
SessionRIDKey contextKey = "session_rid"
|
||||||
RemoteIDKey contextKey = "remote_id"
|
RemoteIDKey contextKey = "remote_id"
|
||||||
UserRolesKey contextKey = "user_roles"
|
UserRolesKey contextKey = "user_roles"
|
||||||
UserEmailKey contextKey = "user_email"
|
UserEmailKey contextKey = "user_email"
|
||||||
@ -58,6 +60,7 @@ func setUserContext(r *http.Request, userCtx *UserContext) *http.Request {
|
|||||||
ctx = context.WithValue(ctx, UserNameKey, userCtx.UserName)
|
ctx = context.WithValue(ctx, UserNameKey, userCtx.UserName)
|
||||||
ctx = context.WithValue(ctx, UserLevelKey, userCtx.UserLevel)
|
ctx = context.WithValue(ctx, UserLevelKey, userCtx.UserLevel)
|
||||||
ctx = context.WithValue(ctx, SessionIDKey, userCtx.SessionID)
|
ctx = context.WithValue(ctx, SessionIDKey, userCtx.SessionID)
|
||||||
|
ctx = context.WithValue(ctx, SessionRIDKey, userCtx.SessionRID)
|
||||||
ctx = context.WithValue(ctx, RemoteIDKey, userCtx.RemoteID)
|
ctx = context.WithValue(ctx, RemoteIDKey, userCtx.RemoteID)
|
||||||
ctx = context.WithValue(ctx, UserRolesKey, userCtx.Roles)
|
ctx = context.WithValue(ctx, UserRolesKey, userCtx.Roles)
|
||||||
|
|
||||||
@ -220,6 +223,16 @@ func GetSessionID(ctx context.Context) (string, bool) {
|
|||||||
return sessionID, ok
|
return sessionID, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSessionID extracts the session ID from context
|
||||||
|
func GetSessionRID(ctx context.Context) (int64, bool) {
|
||||||
|
sessionRIDStr, ok := ctx.Value(SessionRIDKey).(string)
|
||||||
|
sessionRID, err := strconv.ParseInt(sessionRIDStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return sessionRID, ok
|
||||||
|
}
|
||||||
|
|
||||||
// GetRemoteID extracts the remote ID from context
|
// GetRemoteID extracts the remote ID from context
|
||||||
func GetRemoteID(ctx context.Context) (string, bool) {
|
func GetRemoteID(ctx context.Context) (string, bool) {
|
||||||
remoteID, ok := ctx.Value(RemoteIDKey).(string)
|
remoteID, ok := ctx.Value(RemoteIDKey).(string)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user