如何在使用MVC时将id_token添加到OWIN中的response_type?
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "my client id",
ClientSecret = "my secret",
Provider = new GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
Dictionary<string, string> dictionary = new Dictionary<string, string>()
{
{ "response_type", "code id_token" },
{ "openid.realm", "my realm IP" }
};
var redirectUri = WebUtilities.AddQueryString(context.RedirectUri, dictionary);
context.Response.Redirect(redirectUri);
}
}
});
此代码返回错误,因为redirectUri中只包含一个response_type参数。
如何将id_token添加到response_type参数?
仅供参考。这是迁移到OAuth2时需要的,以便引用用户的旧Google ID,因为他们已切换到GUID。
答案 0 :(得分:0)
以下是如何做到的......
GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "my_clientid",
ClientSecret = "my_secret",
Provider = new GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
Dictionary<string, string> dictionary = new Dictionary<string, string>()
{
{ "openid.realm", "my realm URL"},
};
string redirect = context.RedirectUri.Replace("response_type=code", "response_type=code id_token");
var redirectUri = WebUtilities.AddQueryString(redirect, dictionary);
context.Response.Redirect(redirectUri);
},
},
};