参数计数不匹配CreateEndSessionUrl-IdentityModel



我是C#的新手。我正在将.NET IdentityModel与AWS Cognito用户池一起使用,并试图注销以正常工作。CreateEndSessionUrl设置post_logout_redirect_uri,但Cognito需要注销_uri。我正在尝试使用extra参数,但得到的参数计数不匹配。

这是我的代码:

StringDictionary cognitoParameters = new StringDictionary();
cognitoParameters.Add("client_id", OAuthConfiguration.ClientId);
cognitoParameters.Add("logout_uri", OAuthConfiguration.EndsessionEndpointPath);
var endsessionEndpoint = OAuthConfiguration.Authority.TrimEnd('/') + "/" + OAuthConfiguration.EndsessionEndpointPath;
var requestUrl = new RequestUrl(endsessionEndpoint);
var endSessionUrl = requestUrl.CreateEndSessionUrl(
idTokenHint: HttpContext.Current.GetToken(OidcConstants.ResponseTypes.IdToken),
postLogoutRedirectUri: OAuthConfiguration.Host,
state: null,
extra: cognitoParameters
);

CreateEndSessionUrl文档说";额外的参数可以是字符串字典,也可以是具有属性的任意其他类型。在这两种情况下,值都将被序列化为键/值"我想我创建的字符串字典不正确。

我得到的错误是:

Message: Parameter count mismatch.
Exception type: System.Reflection.TargetParameterCountException
Stack trace:
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at IdentityModel.Internal.ValuesHelper.ObjectToDictionary(Object values)
at IdentityModel.Client.RequestUrlExtensions.CreateEndSessionUrl(RequestUrl request, String idTokenHint, String postLogoutRedirectUri, String state, Object extra)
at Indice.Kentico.Oidc.EndSessionOidcHandler.EndSession()
at Indice.Kentico.Oidc.EndSessionOidcHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

有人能帮我理解如何正确格式化并包含extra参数吗?实际上,我不需要idTokenHint、postLogoutRedirectUri,也不需要说明是否可以排除它们。

我发现我需要创建一个Dictionary而不是StringDictionary:

IDictionary cognitoParameters = new Dictionary<string,string>() {
{ "client_id", OAuthConfiguration.ClientId },
{ "logout_uri", OAuthConfiguration.Host.TrimEnd('/') + "/SignOut.ashx" }
};

它现在正在工作。

相关内容

  • 没有找到相关文章

最新更新