如何在Integration Test Project中生成OpenID Connect身份验证令牌?

时间:2018-11-02 03:05:13

标签: c# .net .net-core jwt openid-connect

我在Web应用程序项目的startup.cs中配置openidconnect:

using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
....

if (this.RequireAAD())
{
    // Configure the OWIN pipeline to use cookie auth.
    services.AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie()                
    .AddOpenIdConnect(options =>
    {
        options.ClientId = azureAdConfig.ClientId;
        options.ClientSecret = azureAdConfig.ClientSecret;
        options.Authority = string.Format(azureAdConfig.AADInstance, azureAdConfig.Tenant);
        options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
        options.Resource = azureAdConfig.ResourceURI_Graph;
        // PostLogoutRedirectUri = Configuration["AzureAd:PostLogoutRedirectUri"],
        options.Events = new AuthEvents(azureAdConfig, connectionStringsConfig);
    });

    services.AddAuthorization(options =>
    {
        options.AddPolicy(
            PolicyNames.RequireoneBusinessAdmin,
            policy =>
            {

.....

我正在尝试创建TestServer,它将用于调用api控制器操作进行测试。但是由于API需要令牌进行AAD身份验证,因此我无法使用测试项目生成令牌。

0 个答案:

没有答案