Nexttag.Auth.Identity 1.1.2

dotnet add package Nexttag.Auth.Identity --version 1.1.2
                    
NuGet\Install-Package Nexttag.Auth.Identity -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nexttag.Auth.Identity" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nexttag.Auth.Identity" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Nexttag.Auth.Identity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nexttag.Auth.Identity --version 1.1.2
                    
#r "nuget: Nexttag.Auth.Identity, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nexttag.Auth.Identity@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nexttag.Auth.Identity&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Nexttag.Auth.Identity&version=1.1.2
                    
Install as a Cake Tool

Nexttag.Auth.Identity

ASP.NET Identity integrado: login, registro e troca de senha usando banco local, sem serviço externo.

Instalar

dotnet add package Nexttag.Auth.Identity

Requer .NET 10. Depende de Nexttag.Auth.Jwt (incluso transitivamente).

Registrar (Program.cs)

// Usando o usuário padrão (NexttagIdentityUser)
builder.Services.AddNexttagIdentity<AppDbContext>(builder.Configuration);

// OU com usuário customizado (herda de NexttagIdentityUser)
builder.Services.AddNexttagIdentity<AppDbContext, MeuUsuario>(builder.Configuration);

// ...

app.UseAuthentication();
app.UseAuthorization();

O AppDbContext deve herdar de IdentityDbContext<NexttagIdentityUser, IdentityRole<Guid>, Guid>:

public class AppDbContext : IdentityDbContext<NexttagIdentityUser, IdentityRole<Guid>, Guid>
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
}

Configurar

{
  "ConnectionStrings": {
    "Default": "Host=localhost;Database=meudb;Username=admin;Password=senha"
  },
  "Jwt": {
    "Key": "<chave-secreta-minimo-32-chars>",
    "Issuer": "https://api.seudominio.com.br",
    "Audience": "meu-app",
    "ExpirationMinutes": "480"
  }
}

Regras de senha configuradas internamente:

  • Mínimo 6 caracteres, ao menos 1 dígito e 1 minúscula.
  • Lockout: 5 tentativas → bloqueio de 5 minutos.
  • E-mail único obrigatório.

Usar

Login

public class AuthController(IdentityAuthService<NexttagIdentityUser> auth) : ControllerBase
{
    [HttpPost("login")]
    public async Task<IActionResult> Login(LoginDto dto)
    {
        var result = await auth.LoginAsync(dto.Email, dto.Senha);
        if (!result.IsSuccess) return Unauthorized(result.Error);
        return Ok(result.Value); // { Token, UsuarioId, Email, Nome }
    }
}

Registro

[HttpPost("registro")]
public async Task<IActionResult> Registrar(RegistroDto dto)
{
    var result = await auth.RegistrarAsync(dto.Nome, dto.Email, dto.Senha);
    if (!result.IsSuccess) return BadRequest(result.Error);
    return Ok(result.Value);
}

Alterar senha

[Authorize]
[HttpPut("senha")]
public async Task<IActionResult> AlterarSenha(AlterarSenhaDto dto,
    [FromServices] ICurrentUserProvider usuario)
{
    var result = await auth.AlterarSenhaAsync(usuario.UsuarioId!.Value, dto.SenhaAtual, dto.NovaSenha);
    if (!result.IsSuccess) return BadRequest(result.Error);
    return NoContent();
}

Usuário customizado

public class AppUsuario : NexttagIdentityUser
{
    public string? Departamento { get; set; }
}

// No Program.cs:
builder.Services.AddNexttagIdentity<AppDbContext, AppUsuario>(builder.Configuration);

// No controller, injete IdentityAuthService<AppUsuario>

Receitas

Criar usuário com role após registro:

var result = await auth.RegistrarAsync("João Silva", "joao@email.com", "Senha123");
if (result.IsSuccess)
{
    var user = await userManager.FindByEmailAsync("joao@email.com");
    await userManager.AddToRoleAsync(user!, "operador");
}

Endpoint protegido por role:

[Authorize(Roles = "admin")]
[HttpDelete("{id}")]
public async Task<IActionResult> Excluir(Guid id) { ... }

Notas

  • IdentityAuthService<TUser> usa Result<T> de Nexttag.Common — verifique result.IsSuccess antes de acessar .Value.
  • Lockout retorna AppError.TooManyRequests — mapeie para HTTP 429 no seu ExceptionMiddleware.
  • EmailConfirmed é definido como true no registro — se precisar verificação de e-mail, implemente fluxo separado.
  • Requer migration do EF Core para criar as tabelas do Identity (AspNetUsers, AspNetRoles, etc.).
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Nexttag.Auth.Identity:

Package Downloads
Nexttag.Auth.Identity.Google

Login social com Google para ASP.NET Identity (Nexttag.Auth.Identity): valida o id_token do Google, acha-ou-cria o usuario e emite JWT local. Sem Firebase.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 150 7/28/2026
1.1.0 142 7/28/2026
1.0.0 133 6/7/2026