IdentityServer / IdentityServer3.AccessTokenValidation

OWIN Middleware to validate access tokens from IdentityServer3
Apache License 2.0
90 stars 149 forks source link

UseIdentityServerBearerTokenAuthentication error #29

Closed george-pancescu closed 9 years ago

george-pancescu commented 9 years ago

You have an inconsistency in your code:

This means that you expect to assign an array of strings (string[]) with an IEnumerable... which I don't think you will succeed :)... (only the other way around is possible)

Getting back to your code

var authOptions = 
new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = "https://localhost:44333",
            RequiredScopes = new[] { "api1" }
        });
app.UseIdentityServerBearerTokenAuthentication(authOptions);

This will work due to the fact that even though RequiredScopes is an IEnumerable, you instantiate it with an array of strings; this means that typeof(string[]).IsInstanceOf(authOptions.RequiredScopes) = TRUE

var authOptions = new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = "https://localhost:44333",
            RequiredScopes = GetScopes()
        });
app.UseIdentityServerBearerTokenAuthentication(authOptions);

private static IEnumerable<string> GetScopes()
{
      yield return "api1";
}

typeof(string[]).IsInstanceOf(authOptions.RequiredScopes) = FALSE -> thus no ctor matching

PS: Owin casts the params of the middleware to an object array

leastprivilege commented 9 years ago

That has been fixed on the dev branch.