Token Based Authentication in ASP.NET Core (refreshed)

前端 未结 5 655
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 09:47

I\'m working with ASP.NET Core application. I\'m trying to implement Token Based Authentication but can not figure out how to use new Security System.

My sce

5条回答
  •  孤城傲影
    2020-11-27 10:13

    You can have a look at the OpenId connect samples which illustrate how to deal with different authentication mechanisms, including JWT Tokens:

    https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Samples

    If you look at the Cordova Backend project, the configuration for the API is like so:

    app.UseWhen(context => context.Request.Path.StartsWithSegments(new PathString("/api")), 
          branch => {
                    branch.UseJwtBearerAuthentication(options => {
                        options.AutomaticAuthenticate = true;
                        options.AutomaticChallenge = true;
                        options.RequireHttpsMetadata = false;
                        options.Audience = "localhost:54540";
                        options.Authority = "localhost:54540";
                    });
        });
    

    The logic in /Providers/AuthorizationProvider.cs and the RessourceController of that project are also worth having a look at ;).

    Moreover, I have implemented a single page application with token based authentication implementation using the Aurelia front end framework and ASP.NET core. There is also a signal R persistent connection. However I have not done any DB implementation. Code can be seen here: https://github.com/alexandre-spieser/AureliaAspNetCoreAuth

    Hope this helps,

    Best,

    Alex

提交回复
热议问题