IdentityServer4 IdentityServer3.AccessTokenValidation

后端 未结 2 1680
太阳男子
太阳男子 2021-01-05 16:19

Happy new year to everyone...

I configured an IdentityServer4, and I can make successful ASP.net Core web api calls. But for asp.net framework 4.5.2 web apis, I got

相关标签:
2条回答
  • 2021-01-05 17:01

    Remove the following line in the WebAPI accesstoken validation middleware.

    ValidationMode = ValidationMode.ValidationEndpoint
    

    The result should look like this:

    app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
    {
         Authority = "http://www.abcdefgh.com:5000",
         RequiredScopes = new[] { "AuthorizationWebApiNETFramework" }
    });
    
    0 讨论(0)
  • 2021-01-05 17:06

    In my case, I enabled the log following this: https://identityserver.github.io/Documentation/docsv2/consuming/diagnostics.html

    By default Katana uses the TraceSource mechanism in .NET for logging. Add the following snippet to your config file to enable logging to a file:

    <system.diagnostics>
      <trace autoflush="true" />
    
      <sources>
        <source name="Microsoft.Owin">
          <listeners>
            <add name="KatanaListener" />
          </listeners>
        </source>
      </sources>
    
      <sharedListeners>
        <add name="KatanaListener"
              type="System.Diagnostics.TextWriterTraceListener"
              initializeData="katana.trace.log"
              traceOutputOptions="ProcessId, DateTime" />
      </sharedListeners>
    
      <switches>
        <add name="Microsoft.Owin"
              value="Verbose" />
      </switches>
    </system.diagnostics>
    

    Then I saw the root cause in WebAPI folder log file "katana.trace.log":

        Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware Error: 0 : Authentication failed
    System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    File name: 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
       at IdentityServer3.AccessTokenValidation.ValidationEndpointTokenProvider.<ReceiveAsync>d__1.MoveNext()
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
       at IdentityServer3.AccessTokenValidation.ValidationEndpointTokenProvider.ReceiveAsync(AuthenticationTokenReceiveContext context)
       at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.<AuthenticateCoreAsync>d__0.MoveNext()
    

    After I upgraded the Newtonsoft.Json from 6.0 to 9.01, it worked.

    0 讨论(0)
提交回复
热议问题