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 설명하고이 참조에 대한 코드 샘플입니다 다음 OpenIdConnectAuthenticationOptions 아래와 같이 Startup.Auth.cs에서
, 설치 :
: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는 고객 URL 매개 변수를 요청에서 웹 앱으로 전송하는 것을 지원하지 않습니다. OWIN이 토큰의 유효성을 검사하기 전에 서버가 ID 데이터 공급자로부터 메시지를 받으면'OnMessageReceived'가 시작됩니다. 도움이 되니? –