Home > Enterprise >  Migrating from IdentityServer4.AspNetIdentity 3.x to 4.x
Migrating from IdentityServer4.AspNetIdentity 3.x to 4.x

Time:01-18

When I was about to update the IdentityServer project in my solution, I ran into some issues.

In Login method:

IdentityServer/Quickstart/Account/AccountController.cs

  • ConsentResponse doesn’t contain a definition for Denied.
await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);
  • IClientStore doesn’t contain definition for IsPkceClientAsync.
if (await _clientStore.IsPkceClientAsync(context.ClientId))

In BuildLoginViewModelAsync Method:

IdentityServer/Quickstart/Account/AccountController.cs

  • AccountOptions doesn’t contain definition for WindowsAuthenticationSchemeName
var providers = schemes
    .Where(x => x.DisplayName != null ||
                (x.Name.Equals(AccountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
    )
    .Select(x => new ExternalProvider
    {
        DisplayName = x.DisplayName,
        AuthenticationScheme = x.Name
   }).ToList();
  • AuthorizationRequest doesn’t contain definition for ClientId
var client = await _clientStore.FindEnabledClientByIdAsync(context.ClientId);

In Callback method:

IdentityServer/Quickstart/Account/ExternalController.cs

  • The name ‘ProcessLoginCallbackForOidc’ does not exist in the current context
ProcessLoginCallbackForOidc(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForWsFed(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForSaml2p(result, additionalLocalClaims, localSignInProps);
  • No overload method "SignInAsync" takes 5 arguments.
await HttpContext.SignInAsync(user.Id, name, provider, localSignInProps, additionalLocalClaims.ToArray());

CodePudding user response:

I did some research and came up with the following: You can change as follow:

In Login method: IdentityServer/Quickstart/Account/AccountController.cs

ConsentResponse doesn’t contain a definition for Denied.

await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);

Change to:

await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);

IClientStore doesn’t contain definition for IsPkceClientAsync.

if (await _clientStore.IsPkceClientAsync(context.ClientId))

Change to:

if (context.IsNativeClient())

In BuildLoginViewModelAsync Method: IdentityServer/Quickstart/Account/AccountController.cs

AccountOptions doesn’t contain definition for WindowsAuthenticationSchemeName

var providers = schemes
    .Where(x => x.DisplayName != null ||
                (x.Name.Equals(AccountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
    )
    .Select(x => new ExternalProvider
    {
        DisplayName = x.DisplayName,
        AuthenticationScheme = x.Name
   }).ToList();

Change to:

var providers = schemes
   .Where(x => x.DisplayName != null)
   .Select(x => new ExternalProvider
   {
      DisplayName = x.DisplayName ?? x.Name,
      AuthenticationScheme = x.Name
   }).ToList();

AuthorizationRequest doesn’t contain definition for ClientId

var client = await _clientStore.FindEnabledClientByIdAsync(context.ClientId);

Change to:

var client = await _clientStore.FindEnabledClientByIdAsync(context.Client.ClientId);

In Callback method: IdentityServer/Quickstart/Account/ExternalController.cs

The name ‘ProcessLoginCallbackForOidc’ does not exist in the current context

ProcessLoginCallbackForOidc(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForWsFed(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForSaml2p(result, additionalLocalClaims, localSignInProps);

Change to:

ProcessLoginCallback(result, additionalLocalClaims, localSignInProps);

No overload method "SignInAsync" takes 5 arguments.

await HttpContext.SignInAsync(user.Id, name, provider, localSignInProps, additionalLocalClaims.ToArray());

Change to:

var isuser = new IdentityServerUser(user.Id)
{
    DisplayName = name,
    IdentityProvider = provider,
    AdditionalClaims = additionalLocalClaims
};
await HttpContext.SignInAsync(isuser, localSignInProps);
  •  Tags:  
  • Related