IdentityServer / IdentityServer4.AccessTokenValidation

IdentityServer Access Token Validation for ASP.NET Core
Apache License 2.0
544 stars 214 forks source link

Bearer was not authenticated. Failure message: No token found. #62

Closed Keithleo9008 closed 7 years ago

Keithleo9008 commented 7 years ago

Hi,

For some reason my "access_token" is not being found and validated by the API client when doing a get from the java script client.

I have checked the request headers to make sure it is indeed being set before the request is made to the API and all is good there i see, debugging the HttpContext in the API i see the following: Bearer df0fe103ddee84f3a813a26f9b2feb6224693b801fc81dd95c08f055ef8e5523

So the header is being sent with the request to the API

On the API side my config is as follows:

 app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {

                Authority = this.IdentityServerUrl,//Configuration["identityServer:providerUrl"],
                RequireHttpsMetadata = false,

                ApiName = "BEEAPI", //Set the API Name that will be used as the access scope on the identuty server
                AutomaticAuthenticate = true,
                AutomaticChallenge = false
            });

And the API client is simply configured as:

        public static IEnumerable<ApiResource> GetApiResources()
        {
                return new List<ApiResource>
                {
                    new ApiResource("BEEAPI", "My BEE API")
                };
        }

I can Authenticate against the identity server fine with "id_token" but i cannot access API resources which are protected with the [Authorize] attribute

My logs shows the following:

Callsite    Exception   Level   Logged  Logger  Message
IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationMiddleware.Invoke     Warn    2017-06-13 18:17:12.597 IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationMiddleware    No validator configured for reference token. Ensure ApiName and ApiSecret have been configured to use introspection.
Callsite    Exception   Level   Logged  Logger  Message
Microsoft.Extensions.Logging.LoggingExtensions.AuthenticationSchemeNotAuthenticatedWithFailure      Info    2017-06-13 18:17:12.630 IdentityServer4.AccessTokenValidation.Infrastructure.NopAuthenticationMiddleware    Bearer was not authenticated. Failure message: No token found.

Really hoping somebody can assist i cannot figure this one out

brockallen commented 7 years ago

To validate reference tokens, the library uses introspection (https://identityserver4.readthedocs.io/en/release/endpoints/introspection.html), which requires your API to be configured with an API secret.

leastprivilege commented 7 years ago

Any update on the issue? closing for now - feel free to re-open if it needs further discussion.