Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i solve '"Reference to type 'BaseControlContext" claim.....' for AspNet.Security.OpenIdConnect.Server

I am facing weird issue. I am reading and creating OpenID Connect server with ASOS this article ASOS - AspNet.Security.OpenIdConnect.Server.

I simply created new sample solution and added new subclass AuthorizationProvider class of OpenIdConnectServerProvider and override the virtual method i.e. ExtractAuthorizationRequest

AuthorizationProvider.cs

public class AuthorizationProvider : OpenIdConnectServerProvider
{
    public override Task ExtractAuthorizationRequest(ExtractAuthorizationRequestContext context)
    {
        // If a request_id parameter can be found in the authorization request,
        // restore the complete authorization request stored in the user session.
        if (!string.IsNullOrEmpty(context.Request.RequestId))
        {
            var payload = context.HttpContext.Session.Get(context.Request.RequestId);
            if (payload == null)
            {
                context.Reject(
                    error: OpenIdConnectConstants.Errors.InvalidRequest,
                    description: "Invalid request: timeout expired.");
                return Task.FromResult(0);
            }
            // Restore the authorization request parameters from the serialized payload.
            using (var reader = new BsonReader(new MemoryStream(payload)))
            {
                foreach (var parameter in JObject.Load(reader))
                {
                    // Avoid overriding the current request parameters.
                    if (context.Request.HasParameter(parameter.Key))
                    {
                        continue;
                    }
                    context.Request.SetParameter(parameter.Key, parameter.Value);
                }
            }
        }
        return Task.FromResult(0);
    }
}

Issue: As soon as i add Microsoft.AspNetCore.Identity (2.0.0) NuGet package to my project, context.Reject start giving the following error

"Reference to type 'BaseControlContext" claim it is defined in Microsoft.AspNetCore.Authentication, but it could not be found.

But as soon as I remove Microsoft.AspNetCore.Identity NuGet dependency, the error goes away and all looks fine.

Note:

  1. I am using VS 2017.
  2. I am using dotnetcore 2.0 SDK.
  3. I created solution using .Net Core 2.0.
like image 863
immirza Avatar asked Oct 29 '22 03:10

immirza


1 Answers

Massive changes have been introduced in ASP.NET Core 2.0's authentication stack. The changes are so important that all the authentication middleware written for ASP.NET Core 1.x are not compatible (which includes all the aspnet-contrib projects).

You can read https://github.com/aspnet/Announcements/issues/262 for more information.

The good news is that we have an ASP.NET Core 2.0 RTM-compatible version of ASOS. You can find the 2.0.0-preview1-* bits on the aspnet-contrib MyGet feed (https://www.myget.org/F/aspnet-contrib/api/v3/index.json).

like image 175
Kévin Chalet Avatar answered Nov 29 '22 21:11

Kévin Chalet