asp net core oauth callback 404

2020-01-22 13:07发布

问题:

测试OAuth。。。在2.x上都是正常的,在3.x上不正确,代码如下

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();

        services.AddAuthentication()
        .AddCookie()
        .AddOAuth("GitHub", options =>
        {
            .....
            options.CallbackPath = new PathString("/signin-github");

            options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
            options.TokenEndpoint = "https://github.com/login/oauth/access_token";
            options.UserInformationEndpoint = "https://api.github.com/user";

            options.Events = new OAuthEvents
            {
                OnCreatingTicket = async context =>
                {
                        ........
                }
            };
        });
    }


    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }

认证成功之后回调的地址404.。。看了半天Endpoint相关的没找到相关的

回答1:

我写错了。。。

app.UseAuthorization();---->app.UseAuthentication();



回答2:

services.AddRouting();