您好我有一个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遗留逻辑。我应该把这个逻辑放在哪里?
答案 0 :(得分:0)
您可以使用以下内容:
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);
}
};
});