JWT Claims & Profile Types
Data: 2026-07-07
Fonte: Análise de código coezzion-service-auth
1. Estrutura do JWT
Arquivo: src/Auth.API/Application/Services/Implementations/TokenService.cs:53-58
var claims = new List<Claim>
{
new("schema", authData.Schema),
new("profile", profileId.ToString()),
new(JwtRegisteredClaimNames.UniqueName, userName), // "unique_name"
new(JwtRegisteredClaimNames.Sub, userId.ToString()) // "sub"
};
| Claim | Valor | Exemplo |
|---|---|---|
schema | Schema da organização | "arezzo" |
profile | ProfileId (int as string) | "23" |
unique_name | Nome de usuário | "joao.silva" |
sub | UserId (int as string) | "1542" |
NÃO existe claim cpf. O CPF é retornado no response body (UserToken.Document), não no JWT.
2. TokenValidationParameters
Arquivo: coezzion-nuget-authentication/src/Coezzion.Authentication/Configuration/AuthenticationConfig.cs:20-30
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
// ...
};
ValidateIssuer = false— NÃO valida issuerValidateAudience = false— NÃO valida audienceValidateIssuerSigningKey = true— assinatura HMAC é validada (protege contra tampering)- Sem
NameClaimTypecustomizado → usa defaults do ASP.NET Core
3. Como obter CPF do usuário autenticado
Usa-se IUserProvider do nuget Coezzion.Common.Providers (registrado via DI):
Interface: coezzion-nuget-common/src/Coezzion.Common/Providers/IUserProvider.cs
public interface IUserProvider
{
int GetUserId(); // ClaimTypes.NameIdentifier → sub (parse automático)
string GetSchemaName();
string GetProfile(); // claim "profile" → ProfileId
}
Uso no controller:
var userId = _userProvider.GetUserId(); // int, sem parse manual
var profileStr = _userProvider.GetProfile(); // string, ex: "23"
var user = await _userRepository.GetByIdAsync(userId); // UserModel + Profile
var cpf = user.Cpf;
var profileType = (ProfileType)int.Parse(profileStr);
4. Profile Types (Enum)
Arquivo: coezzion-nuget-common/src/Coezzion.Common/Enums/ProfileType.cs
| Id | Enum | Nome |
|---|---|---|
| 1 | Coezzion_Administrador | Administrador Portal |
| 2 | Coezzion_Usuario | Coezzion Usuário |
| 3 | Easy | Easy |
| 4 | Viewers | Visualizadores |
| 7 | PickUp_And_Delivery | Retire e Entrega |
| 8 | Crm | CRM |
| 9 | Merchan | Merchan |
| 10 | Franchisee | Franqueado |
| 11 | Business_Consultant | Consultor Comercial |
| 12 | Demonstration | Demonstração |
| 13 | Commercial_Manager | Gerente Comercial |
| 20 | Administrador | Administrador |
| 21 | Coordenador | Coordenador |
| 22 | Gerente | Gerente |
| 23 | Vendedor | Vendedor |
| 24 | Gerente_Televendas | Gerente Televendas |
| 25 | Vendedor_Televendas | Vendedor(a) Televendas |
Perfis com bypass Admin: Coezzion_Administrador (1) e Administrador (20)
5. UserModel.Profile (EF Navigation)
Arquivo: coezzion-db-core/src/Core.DB/Entities/UserModel.cs:62-63
public int ProfileId { get; set; }
public ProfileModel Profile { get; set; }
GetByIdAsync já inclui .Include(x => x.Profile) + .Include(x => x.SystemPermissions) + .Include(x => x.Organizations).
6. Padrão existente de permissões por perfil
Arquivo: src/Auth.API/Application/Services/Implementations/AuthService.cs:175
ProfileType profileType = (ProfileType)user.ProfileId;
if (profileType != ProfileType.Coezzion_Administrador &&
profileType != ProfileType.Coezzion_Usuario &&
profileType != ProfileType.Easy &&
profileType != ProfileType.Viewers)
{
validate.AddError("O usuário informado não pode alterar a companhia");
}
Perfis 1-4 são "Coezzion support" — podem trocar de schema/organização. Para o bypass do fix #02, usamos apenas 1 e 20 (mais restritivo).