IdentityServer / IdentityServer4.AccessTokenValidation

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

Quickstart - Protecting an API using Client Credentials -> Adding an API not working on MacOS #64

Closed menjoo closed 7 years ago

menjoo commented 7 years ago

Hi,

I followed along the quickstart and came to this point: Protecting an API using Client Credentials -> Adding an API

I do the following steps from within VS for mac:

  1. Solution -> Add new project
  2. Asp.Net Core WebAPI (target framework is set to .NETCoreApp 1.1)
  3. Add controller like in the quickstart example:
    [Route("identity")]
    [Authorize]
    public class IdentityController : ControllerBase
    {
    [HttpGet]
    public IActionResult Get()
    {
        return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
    }
    }
  4. Add NuGet package IdentityServer4.AccessTokenValidation
  5. And make Startup.cs configure method like this:

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();
    
    app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
    {
        Authority = "http://localhost:5000",
        RequireHttpsMetadata = false,
    
        ApiName = "api1"
    });
    
    app.UseMvc();
    }
  6. And then run it
  7. I get this error
    Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found.
    (Exception from HRESULT: 0x8007007E)
    at Interop.CryptoInitializer.EnsureOpenSslInitialized()
    at Interop.CryptoInitializer..cctor()
    --- End of inner exception stack trace ---
    at Interop.CryptoInitializer.Initialize()
    at Interop.HttpInitializer..cctor()
    --- End of inner exception stack trace ---
    at Interop.HttpInitializer.Initialize()
    at Interop.Http..cctor()
    --- End of inner exception stack trace ---
    at Interop.Http.GetSupportedFeatures()
    at System.Net.Http.CurlHandler..cctor()
    --- End of inner exception stack trace ---
    at System.Net.Http.CurlHandler..ctor()
    at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerMiddleware..ctor(RequestDelegate next, ILoggerFactory loggerFactory, UrlEncoder encoder, IOptions`1 options)
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
    at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next)
    at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
    at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationMiddleware..ctor(RequestDelegate next, IApplicationBuilder app, CombinedAuthenticationOptions options, ILogger`1 logger)
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
    at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next)
    at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
    at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
    at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
    at Game.API.Program.Main(String[] args) in /Users/menno/Git/MyEco/Game.API/Program.cs:line 15
    Abort trap: 6

Edit:

Found the problem.

App seemed to work in docker, so it had to be some environment thingie. After trying some things i found out that i had to do this:

mkdir -p /usr/local/lib ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

after that it works.