我正在尝试在我的 ASP.NET Core 2.0 应用程序中实现 LinkedIn/OAuth 身份验证,我需要将范围设置为{ "r_basicprofile", "r_emailaddress" }
以便我可以使用用户的电子邮件、个人资料图片等。
当我尝试在以下代码中设置范围时,出现以下错误:
无法将属性或索引器“OAuthOptions.Scope”分配给 - 它是只读的。
这是代码:
services.AddOAuth(CookieAuthenticationDefaults.AuthenticationScheme, options => {
options.SignInScheme = "LinkedIn";
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/linkedin-callback";
// Configure the LinkedIn endpoints
options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization",
options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken",
options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original))",
options.Scope = { "r_basicprofile", "r_emailaddress" };
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
OnTicketReceived = OnTicketReceivedCallback
};
})
知道如何设置范围吗?
PS 我试图从我的 ASP.NET Core 1.1 调整代码。此代码在 ASP.NET Core 1.1 应用程序中运行良好。