相关疑难解决方法(0)

.NET Core WebAPI + OpenIdDict(凭据流)和Angular2客户端:401成功登录后(完全重新登录)

我正在尝试使用凭证流创建一个使用OpenIdDict保护的.NET Core Web API的Angular2 SPA.在为这个问题创建一个repro解决方案时,我还详细介绍了自述文件中的所有步骤,所以希望这篇文章对像我这样的新手有用.请在这些存储库中找到完整的repro解决方案:

至于服务器端,我按照OpenIdDict提供的关于此流程的示例(https://github.com/openiddict/openiddict-samples/blob/master/samples/PasswordFlow).以下是最相关的位Startup:

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

    services.AddEntityFrameworkSqlServer()
        .AddDbContext<CatalogContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("Catalog")))
        .AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("Catalog")));

    services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();

    services.AddOpenIddict<ApplicationDbContext>()
        .DisableHttpsRequirement()
        .EnableTokenEndpoint("/connect/token")
        .EnableLogoutEndpoint("/connect/logout")
        .EnableUserinfoEndpoint("/connect/userinfo")
        .AllowPasswordFlow()
        .AllowRefreshTokenFlow()
        .AddEphemeralSigningKey();

    services.AddMvc()
        .AddJsonOptions(options =>
        {
            options.SerializerSettings.ContractResolver =
                new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
        });

    // add my services
    // ...

    services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
    services.AddSwaggerGen();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
    ILoggerFactory loggerFactory,
    IDatabaseInitializer databaseInitializer)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug(); …
Run Code Online (Sandbox Code Playgroud)

asp.net authentication asp.net-web-api openiddict angular

7
推荐指数
1
解决办法
1481
查看次数