AuthenticationBdjobs 1.0.4

dotnet add package AuthenticationBdjobs --version 1.0.4                
NuGet\Install-Package AuthenticationBdjobs -Version 1.0.4                
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="AuthenticationBdjobs" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AuthenticationBdjobs --version 1.0.4                
#r "nuget: AuthenticationBdjobs, 1.0.4"                
#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.
// Install AuthenticationBdjobs as a Cake Addin
#addin nuget:?package=AuthenticationBdjobs&version=1.0.4

// Install AuthenticationBdjobs as a Cake Tool
#tool nuget:?package=AuthenticationBdjobs&version=1.0.4                

How to Add RecruiterAuthorize

To use RecruiterAuthorize in your class in your BaseController like this:


    [ApiController]
    [RecruiterAuthorize]

    public class APIBaseController : ControllerBase
    {
        
    }

Add those in the Program.cs file.

builder.Services.AddSwaggerGen(option =>
{
    option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
    {
        In = ParameterLocation.Header,
        Description = "Enter a valid JSON web token here",
        Name = "Authorization",
        Type = SecuritySchemeType.Http,
        BearerFormat = "JWT",
        Scheme = "Bearer"
    });
    option.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
        {
            new OpenApiSecurityScheme
            {
                Reference = new OpenApiReference
                {
                    Type=ReferenceType.SecurityScheme,
                    Id="Bearer"
                }
            },
            Array.Empty<string>()
        }
    });

});

var jwtSettings = new JwtSettings();

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidateIssuerSigningKey = true,
        ValidIssuer = jwtSettings.Issuer,
        ValidAudience = jwtSettings.Audience,
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Key))
    };
});

app.UseMiddleware<UnauthorizedMiddleware>();

Make a middleware UnauthorizedMiddleware.cs to handle unauthorized access.

public class UnauthorizedMiddleware
{
    private readonly RequestDelegate _next;

    public UnauthorizedMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context)
    {
        await _next(context);

        if (context.Response.StatusCode == StatusCodes.Status401Unauthorized)
        {
            context.Response.ContentType = "application/json";
            var responseData = new
            {
                statusCode = StatusCodes.Status401Unauthorized,
                message = "Unauthorized",
            };

            var json = JsonSerializer.Serialize(responseData);
            await context.Response.WriteAsync(json);
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 56 1/30/2025