feat(spot): added spot jwt support to authorizer in ee version
This commit is contained in:
parent
de691e0f8d
commit
47c33655de
2 changed files with 6 additions and 3 deletions
|
|
@ -12,7 +12,7 @@ func (a *authImpl) IsAuthorized(authHeader string, permissions []string, isExten
|
|||
return nil, err
|
||||
}
|
||||
|
||||
user, err := authUser(a.pgconn, jwtInfo.UserId, jwtInfo.TenantID, int(jwtInfo.IssuedAt.Unix()))
|
||||
user, err := authUser(a.pgconn, jwtInfo.UserId, jwtInfo.TenantID, int(jwtInfo.IssuedAt.Unix()), isExtension)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,18 @@ package auth
|
|||
import (
|
||||
"fmt"
|
||||
"openreplay/backend/pkg/db/postgres/pool"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func authUser(conn pool.Pool, userID, tenantID, jwtIAT int) (*User, error) {
|
||||
func authUser(conn pool.Pool, userID, tenantID, jwtIAT int, isExtension bool) (*User, error) {
|
||||
sql := `SELECT user_id, users.tenant_id, users.name, email, EXTRACT(epoch FROM spot_jwt_iat)::BIGINT AS spot_jwt_iat, roles.permissions
|
||||
FROM users
|
||||
JOIN tenants on users.tenant_id = tenants.tenant_id
|
||||
JOIN roles on users.role_id = roles.role_id
|
||||
WHERE users.user_id = $1 AND users.tenant_id = $2 AND users.deleted_at IS NULL ;`
|
||||
|
||||
if !isExtension {
|
||||
sql = strings.ReplaceAll(sql, "spot_jwt_iat", "jwt_iat")
|
||||
}
|
||||
user := &User{}
|
||||
var permissions []string
|
||||
if err := conn.QueryRow(sql, userID, tenantID).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue