我正在 OnRedirectToIdentityProvider 中设置自定义状态参数值,并能够在 OnMessageReceived 中访问它。可以在MVC Controller中访问此自定义状态值,但该值采用加密格式。如何在Controller中以解密的方式访问它。下面是我的代码:
$(document).on('click','.deletebox',function () {
console.log('box was clicked')
});
在Controller中获得的值如下:private static Task OnRedirectToIdentityProvider(RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
var stateQueryString = notification.ProtocolMessage.State.Split('=');
var protectedState = stateQueryString[1];
var state = notification.Options.StateDataFormat.Unprotect(protectedState);
state.Dictionary.Add("stateUTName", "chandigarh");
notification.ProtocolMessage.State = stateQueryString[0] + "=" + notification.Options.StateDataFormat.Protect(state);
return Task.FromResult(0);
}
private Task OnMessageReceived(MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
string mycustomparameter;
var protectedState = notification.ProtocolMessage.State.Split('=')[1];
var state = notification.Options.StateDataFormat.Unprotect(protectedState);
state.Dictionary.TryGetValue("stateUTName", out mycustomparameter);
return Task.FromResult(0);
}