2017-08-28 1 views
1

私のプロジェクトをasp.netコアにアップグレードしました。しかし、私のCookieAuthneticationメソッドとOpenIdConnectionAuthenticationメソッドは動作しません。彼らは時代遅れになっています。asp.netコア2.0でCookieAuthenticatonとopenidConnect認証を使用できません

Startup.cs設定方法

app.UseCookieAuthentication(new CookieAuthenticationOptions 
      { 
       AuthenticationScheme = "Cookies" 
      }); 

      app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions 
      { 
       AuthenticationScheme = "oidc", 
       SignInScheme = "Cookies", 
       Authority = "http://localhost:5000", 
       RequireHttpsMetadata = false, 
       ClientId = "integapay.client", 
       ClientSecret = "mySecret", 
       ResponseType = "code id_token", 
       Scope = { "openid", "profile", "api.public", "offline_access" }, 
       GetClaimsFromUserInfoEndpoint = true, 
       SaveTokens = true 
      }); 

答えて

2

彼らは設定で

public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddMvc();  
     services.AddAuthentication(options => { 
         options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
         options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; 
        }) 
     .AddCookie() 
     .AddOpenIdConnect(options => SetOpenIdConnectOptions(options)); 
    } 
    private void SetOpenIdConnectOptions(OpenIdConnectOptions options) 
    {   
     options.Authority = Configuration["auth:oidc:authority"]; 
     options.ClientId = Configuration["auth:oidc:clientid"]; 
     options.RequireHttpsMetadata = false; 
     options.ClientSecret = Configuration["auth:oidc:clientSecret"]; 
     options.SignInScheme = "Cookies"; 
     options.SaveTokens = true; 
     options.GetClaimsFromUserInfoEndpoint = true; 
     options.ResponseType = "code id_token"; 

     options.Scope.Add("openid"); 
     options.Scope.Add("profile"); 
     options.Scope.Add("api_back"); 
     options.Scope.Add("offline_access"); 
    } 

app.UseAuthentication(); 

希望を呼び出す必要がありますだけであなたを呼び出すConifgurationサービスパートにそれを移動しますこれは役に立ちます。 :)

関連する問題