2017-11-18 3 views
0

저는 Core 1.0에서 Core 2.0으로 마이그레이션하고 필요로하는 코드로 작업 중이며 서비스 인증에서 필드를 사용하고 마이그레이션해야합니다. Core 2.0에서 필드를 사용하려면 어떻게해야합니까? (나도 Microsoft의 마이그레이션 문서를 검토하지만, 아무것도 찾을 수 없습니다.) https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2xASP.NET Core 1.0으로 ASP.NET Core 2.0으로 업그레이드 ConfigureServices의 인증 업그레이드 - Core 2.0에서 Fields를 사용하려면 어떻게해야합니까?

public void ConfigureServices(IServiceCollection services) 

그리고 난 다음에 문제가 :

Fields = { "email", "last_name", "first_name" }, 
(내가 어떻게 추가합니까 코어 2.0에서 다음)

다음은 아래 코드입니다.

ASP.NET 코어 1.0

app.UseFacebookAuthentication(new FacebookOptions 
{ 
    AppId = Configuration["Authentication:Test:Facebook:AppId"], 
    AppSecret = Configuration["Authentication:Test:Facebook:AppSecret"], 
    Fields = { "email", "last_name", "first_name" }, 
}); 

필요성 2.0

services.AddAuthentication().AddFacebook(facebookOptions => 
{ 
    facebookOptions.AppId = Configuration["Authentication:Test:Facebook:AppId"]; 
    facebookOptions.AppSecret = Configuration["Authentication:Test:Facebook:AppSecret"]; 
}); 

답변

1

Fields가 읽기 전용 ASP.NET 코어로 마이그레이션하는,하지만 당신은 그 내용을 수정할 수 있습니다. 귀하의 예를 촬영, 코드 레벨 마이그레이션은 다음과 같습니다 이러한 set by default을 그대로

services.AddAuthentication().AddFacebook(facebookOptions => 
{ 
    facebookOptions.AppId = Configuration["Authentication:Test:Facebook:AppId"]; 
    facebookOptions.AppSecret = Configuration["Authentication:Test:Facebook:AppSecret"]; 
    facebookOptions.Fields.Clear(); 
    facebookOptions.Fields.Add("email"); 
    facebookOptions.Fields.Add("last_name"); 
    facebookOptions.Fields.Add("first_name"); 
}); 

그러나이 실제로 필요하지 않습니다. 심지어 ASP.NET 코어의 previous version 필요없는 것처럼

public FacebookOptions() 
{ 
    // ... 
    Fields.Add("name"); 
    Fields.Add("email"); 
    Fields.Add("first_name"); 
    Fields.Add("last_name"); 
    // ... 
} 

그것은 보이지만, 그냥 (name없이) 기본값을 대체 한대로 코드는 잘 작동합니다 : 소스에서 코드를 참조하십시오 . 실제로 name을 요청하지 않으려면 facebookOptions.Fields.Remove(“name”)을 사용할 수 있습니다.

관련 문제