generated from VLADIMIR/template
update claims
This commit is contained in:
+22
-7
@@ -37,7 +37,7 @@ func (s *server) Signup(ctx context.Context, req *proto.SignupReq) (*proto.Signu
|
||||
}
|
||||
|
||||
func (s *server) DeleteAccount(ctx context.Context, req *proto.DeleteAccountReq) (*proto.DeleteAccountRsp, error) {
|
||||
claims, ok := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, ok := processor_jwt.ClaimsFromContext(ctx)
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.Unauthenticated, "claims is not provided")
|
||||
}
|
||||
@@ -152,7 +152,10 @@ func (s *server) Refresh(ctx context.Context, req *proto.RefreshReq) (*proto.Ref
|
||||
}
|
||||
|
||||
func (s *server) GetUsers(ctx context.Context, req *proto.GetUsersReq) (*proto.GetUsersRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
return nil, claimsErr
|
||||
}
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
@@ -186,7 +189,10 @@ func (s *server) GetUserById(ctx context.Context, req *proto.GetUserByIdReq) (*p
|
||||
}
|
||||
|
||||
func (s *server) GetMe(ctx context.Context, req *proto.GetMeReq) (*proto.GetMeRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
return nil, claimsErr
|
||||
}
|
||||
user, err := s.usersService.GetUserByID(ctx, claims.UserID)
|
||||
if err != nil {
|
||||
return &proto.GetMeRsp{
|
||||
@@ -200,7 +206,10 @@ func (s *server) GetMe(ctx context.Context, req *proto.GetMeReq) (*proto.GetMeRs
|
||||
}
|
||||
|
||||
func (s *server) AddUserRole(ctx context.Context, req *proto.AddUserRoleReq) (*proto.AddUserRoleRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
return nil, claimsErr
|
||||
}
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
@@ -213,7 +222,10 @@ func (s *server) AddUserRole(ctx context.Context, req *proto.AddUserRoleReq) (*p
|
||||
}
|
||||
|
||||
func (s *server) DeleteUserRole(ctx context.Context, req *proto.DeleteUserRoleReq) (*proto.DeleteUserRoleRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
return nil, claimsErr
|
||||
}
|
||||
if !roles.HasRole(claims, roles.Admin) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
@@ -226,7 +238,10 @@ func (s *server) DeleteUserRole(ctx context.Context, req *proto.DeleteUserRoleRe
|
||||
}
|
||||
|
||||
func (s *server) GetPermissions(ctx context.Context, req *proto.GetPermissionsReq) (*proto.GetPermissionsRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, claimsErr := claimsFromContext(ctx)
|
||||
if claimsErr != nil {
|
||||
return nil, claimsErr
|
||||
}
|
||||
permissions := s.uiService.GetPermissions(claims.Roles)
|
||||
return &proto.GetPermissionsRsp{
|
||||
Permissions: permissions,
|
||||
@@ -234,7 +249,7 @@ func (s *server) GetPermissions(ctx context.Context, req *proto.GetPermissionsRe
|
||||
}
|
||||
|
||||
func (s *server) ChangeUserPassword(ctx context.Context, req *proto.ChangeUserPasswordReq) (*proto.ChangeUserPasswordRsp, error) {
|
||||
claims, ok := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
claims, ok := processor_jwt.ClaimsFromContext(ctx)
|
||||
if !ok || claims == nil {
|
||||
return nil, status.Error(codes.Unauthenticated, "Требуется авторизация")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user