在带有Identity Framework 2的ASP.NET 4中,我可以使用我自己的参数附加redirectUri,例如Google用于将登录限制为如下所示的域的“ hd”参数:
var googleAuthOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "redacted",
ClientSecret = "redacted",
Provider = new CustomGoogleProvider
{
OnApplyRedirect = context =>
{
var redirect = context.RedirectUri;
redirect += "&hd=contoso.com";
context.Response.Redirect(redirect);
}
}
};
app.UseGoogleAuthentication(googleAuthOptions);
但是我找不到有关如何使用带有Identity Framework 3的新ASP.NET Core 1执行相同操作的文档。
在GitHub上的源代码的帮助下,我想出了一个可行的解决方案,非常类似于问题中的解决方案:
app.UseGoogleAuthentication(options => {
options.ClientId = Configuration["Authentication:Google:ClientId"];
options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
options.Events = new OAuthEvents()
{
OnRedirectToAuthorizationEndpoint = context =>
{
context.Response.Redirect(context.RedirectUri + "&hd=contoso.com");
return Task.FromResult(0);
}
};
});
但这是这样做的正确方法,还是有更好的方法?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句