使用IdentityModel.OidcClient登录时出现未经授权的错误

问题描述 投票:0回答:1

我负责开发一个必须使用OpenID登录的跨平台应用程序。该应用程序是在 Xamarin.Forms 中开发的,但我必须将其迁移到 MAUI。要登录应用程序,我使用 IdentityModel.OidcClient 库。身份验证服务器功能齐全。我不是开发和维护服务器的人。

Xamarin.Forms 应用程序能够毫无问题地登录并获取完整的凭据:访问令牌、刷新令牌、过期、声明...我使用的库的版本是 IdentityModel.OidcClient 5.2.1。身份验证过程遵循此链接中描述的步骤:使用 Open Identity Connect 和 OAuth 在 Xamarin Forms 中进行身份验证

我现在正在尝试使用最新版本的库(6.0.0)将此过程迁移到 MAUI。为此,我做的第一件事是下载 MAUI 的示例代码 并仅更改以下内容:

  • MauiProgram.cs:OIDC 选项(权限、ClientId、范围、RedirectUri)

     // setup OidcClient
     builder.Services.AddSingleton(new OidcClient(new()
     {
         Authority = "https://www.realdomain.es/openid/more/path/",
         ClientId = "myclientid",
         Scope = "openid",
         RedirectUri = "myscheme://localhost",
         Browser = new MauiAuthenticationBrowser()
     }));
    
  • MauiAuthenticationBrowser.cs:RequestUrl(与 RedirectUri 相同)

     var url = new RequestUrl("myscheme://localhost")
         .Create(new Parameters(result.Properties));
    
  • WebAuthenticationCallbackActivity.cs:CALLBACK_SCHEME。

     const string CALLBACK_SCHEME = "myscheme";
    

在 Android 设备上运行应用程序并登录时,浏览器无法打开,并且出现此错误:

未授权:推送授权参数失败

我无法找到与此错误相关的任何内容。有谁知道会发生什么?

maui openid-connect unauthorized identitymodel
1个回答
0
投票

我在库的源代码中查找了错误消息,发现了以下日志

_logger.LogDebug("The IdentityProvider contains a pushed authorization request endpoint. Automatically pushing authorization parameters. Use DisablePushedAuthorization to opt out.");

所以解决方案是在OidcClient选项中添加

DisablePushedAuthorization = true

// setup OidcClient
builder.Services.AddSingleton(new OidcClient(new()
{
    Authority = "https://www.realdomain.es/openid/more/path/",
    ClientId = "myclientid",
    Scope = "openid",
    RedirectUri = "myscheme://localhost",
    Browser = new MauiAuthenticationBrowser(),
    DisablePushedAuthorization = true // To avoid error > Failed to push authorization parameters
}));
© www.soinside.com 2019 - 2024. All rights reserved.