OAuth2回调没有击中处理程序

时间:2017-09-07 16:33:07

标签: asp.net-mvc oauth asp.net-core oauth-2.0

当我通过重定向回复到我的回调网址进行身份验证的服务器时,我的代码似乎不知道如何处理请求 - 好像我错过了一个处理程序。

我认为CallbackPath属性会将其连接起来并将传入的请求传递给我的处理程序,这是不正确的?

我刚刚从我的应用中获得了404,该网址的代码为= XXXX等。

这是我的代码

public Startup(IConfiguration configuration)
{
  Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{

  string authScheme = CookieAuthenticationDefaults.AuthenticationScheme;

  services.AddAuthentication(o =>
  {
    o.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    o.DefaultAuthenticateScheme = "MyAuthScheme";
    o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;

  }).AddOAuth(authScheme, options =>
  {
     options.ClientId = "xxxxxxxxxxxxxxxxxxxxxxxx";
    options.AuthorizationEndpoint = "https://example.com/adfs/oauth2/authorize?resource=https://example.net/";
    options.TokenEndpoint = "https://example.com/adfs/oauth2/token";
    options.CallbackPath = new Microsoft.AspNetCore.Http.PathString("/signin-myauthserver");
    options.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx";

  });


  services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());


}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  if (env.IsDevelopment())
  {
    app.UseDeveloperExceptionPage();
    app.UseBrowserLink();
  }
  else
  {
    app.UseExceptionHandler("/Error");
  }

  app.UseAuthentication();

  app.UseStaticFiles();

  app.UseMvc(routes =>
  {
    routes.MapRoute(
              name: "default",
              template: "{controller}/{action=Index}/{id?}");
  });
}

0 个答案:

没有答案