[英]AWS cognito ASP.NET Core MVC throws 'invalid_client'
[英]AWS Cognito with OpenID failing with .NET Core gives error of *Error redeeming code: invalid_client*
環境
背景
我們在用戶機器上運行了多個 windows 應用程序(WPF 和 WinForms)。 用戶在 AWS Cognito 的自定義用戶池中進行管理。 與其他服務的聯合存在,但在 scope 之外進行這項工作。 SSO 應用程序會顯示一個登錄屏幕,用戶可以在其中輸入他們的憑據並通過 Cognito 進行身份驗證,然后返回一個身份驗證代碼。 登錄機制是通過 OpenID Connect。
問題陳述
用戶通過 Cognito 成功通過身份驗證,但 OIDC 登錄調用給出如下錯誤消息:-
Error redeeming code: invalid_client / no description
從 Cognito 收到的響應如下,結果代碼為成功:-
http://localhost/myBusinessApp?code=5a0507ed-5230-408d-&state=KHfMkdZphxxxxxxxxxx
**代碼 **
認證應用
var options = new OidcClientOptions()
{
Authority = _authenticationConfig.Value.Authority,
ClientId = _authenticationConfig.Value.ClientId,
ClientSecret = _authenticationConfig.Value.ClientSecret,
Scope = _authenticationConfig.Value.Scope,
RedirectUri = _authenticationConfig.Value.RedirectUri,
Browser = new CEFBrowser(),
Policy = new Policy()
{
Discovery = new DiscoveryPolicy()
{
ValidateIssuerName = false , /* added for Cognito only */
ValidateEndpoints = false /* added for Cognito only */
}
},
Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode /* default, but just for clarity */
};
_oidcClient = new IdentityModel.OidcClient.OidcClient(options);
LoginResult result;
try
{
result = await _oidcClient.LoginAsync();
}
catch (Exception ex)
{
Message.Text = $"Unexpected Error: {ex.Message}";
return;
}
if (result.IsError)
// Log error (always happen)
瀏覽器調用 Cognito
這總是成功重定向到配置的 RedirectUrl
webBrowser.LoadingStateChanged += (s, e) =>
{
var url = e.Browser.MainFrame.Url;
if (url.StartsWith(_options.EndUrl))
{
result = new BrowserResult()
{
ResultType = BrowserResultType.Success,
Response = url
};
signal.Release();
webBrowser.Dispatcher.Invoke(() => window.Close());
}
};
認知配置
https://console.aws.amazon.com/cognito/users/?region=us-east-1#/pool/us-east-1_spXXXX/users?_k=m7yyyy
)authorise
和login
端點時會出現這種情況Authorization Code Grant
openid profile email
已經探索的教程
提琴手響應
最后在添加單元測試支持后,我意識到由於數據結構不正確,ClientSecret 沒有通過。 添加后,該應用程序正常運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.