Coder Social home page Coder Social logo

auth0-samples / auth0-aspnetcore-webapi-samples Goto Github PK

View Code? Open in Web Editor NEW
187.0 30.0 175.0 129 KB

Auth0 Integration Samples for ASP.NET Core WebAPI Services

Home Page: https://auth0.com/docs/quickstart/backend/aspnet-core-webapi

License: MIT License

C# 74.32% PowerShell 3.77% Shell 4.29% Dockerfile 17.62%
quickstart auth0 authentication aspnet api dx-sdk-quickstart

auth0-aspnetcore-webapi-samples's People

Contributors

alexisluque avatar damieng avatar dependabot[bot] avatar evansims avatar frederikprijck avatar hawxy avatar iamsunny avatar jerriep avatar jimmyjames avatar joshcanhelp avatar layersofabstraction avatar lbalmaceda avatar snyk-bot avatar widcket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

auth0-aspnetcore-webapi-samples's Issues

It doesn't work

There appears to be no way to make this work. The calls always result in unauthorized 401 errors.

ValidateIssuerSigningKey for RSA JWT

in the 01-Authorization example or in the official website there is nothing about the validation issuer signing key,
but in old versions ".net framework", there was an example in validation it,

in this example, is this just fine to validate the token?

var domain = $"https://{Configuration["Auth0:Domain"]}/";
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
  options.Authority = domain;
  options.Audience = Configuration["Auth0:Audience"];
});

or I need to write IssuerSigningKeyResolver to get jwks from the ".well-known/jwks.json" path, like this?

var domain = $"https://{Configuration["Auth0:Domain"]}/";
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
  options.Authority = domain;
  options.Audience = Configuration["Auth0:Audience"];
  options.TokenValidationParameters = new TokenValidationParameters
     {
         ValidateIssuerSigningKey = true,
         IssuerSigningKeyResolver = (token, securityToken, kid, parameters) =>
         {
             var client = new HttpClient();
             var jwksUri = new Uri($"{domain}.well-known/jwks.json");
             var jwksJson = client.GetStringAsync(jwksUri).GetAwaiter().GetResult();

             var jwks = JsonConvert.DeserializeObject<JsonWebKeySet>(jwksJson);
             return jwks.Keys;
         }
     };

});

No SecurityTokenValidator available for token: <access_token>

Following the same setup,

Here is a fiddler request

Host: localhost:5000
Connection: keep-alive
Authorization: Bearer jXFxGSgB3thqIQ0O
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Access-Control-Allow-Origin: *
Accept: application/json, text/plain, */*
Referer: http://localhost:4200/home/devices
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8

If I subscribe to the OnChallenge event:

 var options = new JwtBearerOptions
            {
                Audience = Configuration["Auth0:ApiIdentifier"],
                Authority = $"https://{Configuration["Auth0:Domain"]}/",
                Events = new JwtBearerEvents
                {
                    OnChallenge = context =>
                    {
                        var ctx = context;
                        return Task.CompletedTask;
                    }
            };

I am getting the following error:
No SecurityTokenValidator available for token: <access_token>

This does not work

I've followed this and the handler never finds the claims because their always empty. Either the documentation is incomplete or this is out of date because it doesn't work and there no decent documentation on how to do this. None of the guides on the website work either.

A comment on this sample

The sample makes use of Fiddler, so it might be nice to find a few words on how to set this tool up to match the experience shown at

image

DotNetCore v2.0 is buggy?

The template DotNetCore v1.1 work fine, but this one with DotNetCore v2.0 the ping method return code 401:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 OPTIONS http://localhost:5000/api/ping/secure
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
Policy execution successful.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 18.6146ms 204
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/api/ping/secure application/json
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
Policy execution successful.
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed for user: (null).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
info: Microsoft.AspNetCore.Mvc.ChallengeResult[1]
Executing ChallengeResult with authentication schemes ().
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[2]
Successfully validated the token.
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[12]
AuthenticationScheme: Bearer was challenged.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action WebAPIApplication.Controllers.PingController.PingSecured (WebAPIApplication) in 482.9601ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 522.6374ms 401

No Error message in response

There's no error message displayed while calling the API without a proper access_token

image

image

It should be displayed an error message specifing the error code.

GetUserInfoAsync() - All properties are null beside 'sub'

I have used your sample code to retrieve the user information. But the response only includes the 'sub' claim. All the other properties are null.

Also a manuel request with Postman has the same outcome.

I only get a real result if I request the userinfo-endpoint with the POST method and add the access_token to the post data. Is the API outdated or do I something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.