嗨,我有一个 mvc 网站,我必须将它迁移到 net core 2。旧网站有 cookie 和 facebook 身份验证,配置如下:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
LoginPath = "LoginPath",
CookieName = "CookieName",
CookieDomain = "CookieDomain",
CookieSecure = CookieSecureOption.SameAsRequest,
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx =>
{
//Some logic and redirection
}
}
});
app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
CallbackPath = "CallbackPath",,
AppId = "AppId",
AppSecret = "AppSecret",
Provider = new FacebookAuthenticationProvider
{
OnApplyRedirect = (context) =>
{
//Some logic and redirection
},
OnAuthenticated = (context) =>
{
//Some logic and add claim
}
}
});
我现在有:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(
options =>
{
options.LoginPath = "LoginPath";
options.CookieName = "CookieName";
options.CookieDomain = "CookieDomain";
})
.AddFacebook(options =>
{
CallbackPath = "CallbackPath";
AppId = "AppId";
AppSecret = "AppSecret";
});
但是我找不到“提供者”来放置我拥有的 OnApplyRedirect 和 OnAuthenticated 遗留逻辑。我应该把这个逻辑放在哪里?
您可以使用以下内容:
services.AddAuthentication().AddFacebook(options =>
{
options.ClientId = Configuration.GetSection("Facebook:ApplicationId").Value;
options.ClientSecret = Configuration.GetSection("Facebook:Password").Value;
options.Events = new OAuthEvents
{
OnCreatingTicket = context =>
{
// do something with context
return Task.FromResult<object>(null);
}
};
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句