Meyer.EndpointAuthentication 1.0.0-preview2

This is a prerelease version of Meyer.EndpointAuthentication.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Meyer.EndpointAuthentication --version 1.0.0-preview2
NuGet\Install-Package Meyer.EndpointAuthentication -Version 1.0.0-preview2
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="Meyer.EndpointAuthentication" Version="1.0.0-preview2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Meyer.EndpointAuthentication --version 1.0.0-preview2
#r "nuget: Meyer.EndpointAuthentication, 1.0.0-preview2"
#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 Meyer.EndpointAuthentication as a Cake Addin
#addin nuget:?package=Meyer.EndpointAuthentication&version=1.0.0-preview2&prerelease

// Install Meyer.EndpointAuthentication as a Cake Tool
#tool nuget:?package=Meyer.EndpointAuthentication&version=1.0.0-preview2&prerelease

Meyer.EndpointAuthentication

This library is used to add Authentication and Authorization to WebAPI services.

Setting up the service

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddEntityFrameworkNpgsql();

    ...
        
    services.AddEndpointAuthentication(o => o.UseNpgsql(ConnectionString));

    ...
}

Note: You can use any Entity Framework data store.

Adding the middleware

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseRequestOAuth();

    ...

    app.UseSignedMessage();

    app.UseMvc();
}

Using Authorization

// POST api/orders
[HttpPost]
[Authorize(Roles = "AuthenticatedUser")]
public void Post([FromBody] Order value)
{
    ...
}

[HttpPut("{id}")]
[Authorize(Roles = "AuthenticatedUser")]
public ActionResult Put(int id, [FromBody] Order value)
{
     ...
}

Configuring the database

In the Package Manager Console:

PM> Add-Migration -Context EndpointDataContext -Name EPAuth
PM> Update-Database

Seed the Database

Generate the Administrator and AuthenticatedUser roles and create the Admin account.

public virtual void SeedDatabase()
{
    Role administrator = default(Role);
    User admin = default(User);

    administrator = Roles.SingleOrDefault(r => r.RoleName == "Administrator");
    if (administrator == default(Role))
    {
        administrator = new Role() { RoleName = "Administrator", Description = "Database Administator" };
        Roles.Add(administrator);
    }

    Role authUser = Roles.SingleOrDefault(r => r.RoleName == "AuthenticatedUser");
    if (authUser == default(Role))
    {
        authUser = new Role { RoleName = "AuthenticatedUser", Description = "Authenticated User Account" };
        Roles.Add(authUser);
    }

    admin = Users.SingleOrDefault(u => u.UserName == "Admin");
    if (admin == default(User))
    {
        admin = new User() { UserName = "Admin", Password = "password", IsActive = true, UserRoles = new List<UserRole>() };
        admin.AddRole(administrator);
        admin.AddRole(authUser);
            
        admin.GenerateNewUserKey();
            
        Users.Add(admin);
    }

    SaveChanges();
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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