0
是否可以將自定義查詢參數添加到AzureAD OAuth流的redirect_uri中?azuread oauth redirect_uri查詢參數
我們已經嘗試過,但是當OAuth流重定向回redirect_uri時,我們添加的任何查詢參數都已被剝離。我想知道是否有一種方法來配置AzureAD應用程序來保持這種自定義查詢參數
是否可以將自定義查詢參數添加到AzureAD OAuth流的redirect_uri中?azuread oauth redirect_uri查詢參數
我們已經嘗試過,但是當OAuth流重定向回redirect_uri時,我們添加的任何查詢參數都已被剝離。我想知道是否有一種方法來配置AzureAD應用程序來保持這種自定義查詢參數
是否可以將自定義查詢參數添加到AzureAD OAuth流的redirect_uri?
是的,如果您將Azure AD與OWIN集成,則很容易添加自定義查詢參數。這個問題也被討論here,這是供你參考代碼示例:
在Startup.Auth.cs,設置如下面的OpenIdConnectAuthenticationOptions:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
//...
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = OnRedirectToIdentityProvider,
MessageReceived = OnMessageReceived
},
});
注入的自定義參數使用RedirectToIdentityProvider:
private 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("mycustomparameter", "myvalue");
notification.ProtocolMessage.State = stateQueryString[0] + "=" + notification.Options.StateDataFormat.Protect(state);
return Task.FromResult(0);
}
然後使用的messageReceived將其解壓:
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("mycustomparameter", out mycustomparameter);
return Task.FromResult(0);
}
感謝您的回覆。我可以看到我有點不清楚。 我們有一個參數,寧願在redirect_uri上返回,而不是作爲狀態的一部分,因此我們可以在檢查id_token和狀態之前決定執行哪個邏輯分支,但是我們直接添加的任何動態查詢參數到redirect_uri被刪除當驗證的請求被重定向到request_uri。 我希望這是有道理的。 –
目前,Azure AD不支持將客戶網址參數從請求傳輸到網絡應用。一旦你的服務器從OWIN驗證令牌之前的身份數據提供者獲得消息,'OnMessageReceived'將被觸發。它有幫助嗎? –