CurrentMCPAuthInfo extracts the current authenticated user, enterprise and role.
(ctx context.Context)
| 105 | |
| 106 | // CurrentMCPAuthInfo extracts the current authenticated user, enterprise and role. |
| 107 | func CurrentMCPAuthInfo(ctx context.Context) (userID int64, eid int64, role int64, err error) { |
| 108 | tokenInfo := auth.TokenInfoFromContext(ctx) |
| 109 | if tokenInfo == nil { |
| 110 | return 0, 0, 0, errors.New("missing MCP authentication context") |
| 111 | } |
| 112 | |
| 113 | userID, err = CurrentMCPUserID(ctx) |
| 114 | if err != nil { |
| 115 | return 0, 0, 0, err |
| 116 | } |
| 117 | |
| 118 | if tokenInfo.Extra != nil { |
| 119 | if v, ok := tokenInfo.Extra["user_eid"]; ok { |
| 120 | switch value := v.(type) { |
| 121 | case int64: |
| 122 | eid = value |
| 123 | case int: |
| 124 | eid = int64(value) |
| 125 | case float64: |
| 126 | eid = int64(value) |
| 127 | case string: |
| 128 | eid, _ = strconv.ParseInt(value, 10, 64) |
| 129 | } |
| 130 | } |
| 131 | if v, ok := tokenInfo.Extra["user_role"]; ok { |
| 132 | switch value := v.(type) { |
| 133 | case int64: |
| 134 | role = value |
| 135 | case int: |
| 136 | role = int64(value) |
| 137 | case float64: |
| 138 | role = int64(value) |
| 139 | case string: |
| 140 | role, _ = strconv.ParseInt(value, 10, 64) |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | return userID, eid, role, nil |
| 145 | } |
| 146 | |
| 147 | // CurrentMCPAPIKeyID extracts the current MCP API key ID from the request context. |
| 148 | func CurrentMCPAPIKeyID(ctx context.Context) (int64, error) { |
no test coverage detected