【问题标题】:Migrating from IdentityServer4.AspNetIdentity 3.x to 4.x从 IdentityServer4.AspNetIdentity 3.x 迁移到 4.x
【发布时间】:2022-01-15 03:39:38
【问题描述】:

当我准备在我的解决方案中更新 IdentityServer 项目时,我遇到了一些问题。

在登录方式中:

IdentityServer/Quickstart/Account/AccountController.cs

  • ConsentResponse 不包含 Denied 的定义。
await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);
  • IClientStore 不包含 IsPkceClientAsync 的定义。
if (await _clientStore.IsPkceClientAsync(context.ClientId))

在 BuildLoginViewModelAsync 方法中:

IdentityServer/Quickstart/Account/AccountController.cs

  • AccountOptions 不包含 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 不包含 ClientId 的定义
var client = await _clientStore.FindEnabledClientByIdAsync(context.ClientId);

在回调方法中:

IdentityServer/Quickstart/Account/ExternalController.cs

  • 当前上下文中不存在名称“ProcessLoginCallbackForOidc”
ProcessLoginCallbackForOidc(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForWsFed(result, additionalLocalClaims, localSignInProps);
ProcessLoginCallbackForSaml2p(result, additionalLocalClaims, localSignInProps);
  • 没有重载方法“SignInAsync”需要 5 个参数。
await HttpContext.SignInAsync(user.Id, name, provider, localSignInProps, additionalLocalClaims.ToArray());

【问题讨论】:

    标签: c# asp.net-core identityserver4


    【解决方案1】:

    我做了一些研究,得出以下结论:您可以更改如下:

    在登录方式中: IdentityServer/Quickstart/Account/AccountController.cs

    ConsentResponse 不包含 Denied 的定义。

    await _interaction.GrantConsentAsync(context, ConsentResponse.Denied);
    
    Change to:
    
    await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied);
    

    IClientStore 不包含 IsPkceClientAsync 的定义。

    if (await _clientStore.IsPkceClientAsync(context.ClientId))
    
    Change to:
    
    if (context.IsNativeClient())
    

    在 BuildLoginViewModelAsync 方法中: IdentityServer/Quickstart/Account/AccountController.cs

    AccountOptions 不包含 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 不包含 ClientId 的定义

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

    在回调方法中: IdentityServer/Quickstart/Account/ExternalController.cs

    当前上下文中不存在名称“ProcessLoginCallbackForOidc”

    ProcessLoginCallbackForOidc(result, additionalLocalClaims, localSignInProps);
    ProcessLoginCallbackForWsFed(result, additionalLocalClaims, localSignInProps);
    ProcessLoginCallbackForSaml2p(result, additionalLocalClaims, localSignInProps);
    
    Change to:
    
    ProcessLoginCallback(result, additionalLocalClaims, localSignInProps);
    

    没有重载方法“SignInAsync”需要 5 个参数。

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-29
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多