コード例 #1
0
    public void ConfigurePerTenantAuthentication_UseChallengeScheme()
    {
        var services = new ServiceCollection();

        services.AddOptions();
        services.AddAuthentication().AddCookie().AddOpenIdConnect();
        services.AddMultiTenant <TestTenantInfo>()
        .WithPerTenantAuthentication();
        var sp = services.BuildServiceProvider();

        var ti1 = new TestTenantInfo
        {
            Id              = "id1",
            Identifier      = "identifier1",
            ChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme
        };

        var accessor = sp.GetRequiredService <IMultiTenantContextAccessor <TestTenantInfo> >();

        accessor.MultiTenantContext = new MultiTenantContext <TestTenantInfo> {
            TenantInfo = ti1
        };

        var options = sp.GetRequiredService <IAuthenticationSchemeProvider>();

        Assert.Equal(ti1.ChallengeScheme, options.GetDefaultChallengeSchemeAsync().Result.Name);
    }
コード例 #2
0
    public void ConfigurePerTenantAuthentication_UseOpenIdConnectConvention()
    {
        var services = new ServiceCollection();

        services.AddOptions();
        services.AddAuthentication().AddOpenIdConnect();
        services.AddMultiTenant <TestTenantInfo>()
        .WithPerTenantAuthentication();
        var sp = services.BuildServiceProvider();

        var ti1 = new TestTenantInfo
        {
            Id                        = "id1",
            Identifier                = "identifier1",
            OpenIdConnectAuthority    = "https://tenant",
            OpenIdConnectClientId     = "tenant",
            OpenIdConnectClientSecret = "secret"
        };

        var accessor = sp.GetRequiredService <IMultiTenantContextAccessor <TestTenantInfo> >();

        accessor.MultiTenantContext = new MultiTenantContext <TestTenantInfo> {
            TenantInfo = ti1
        };

        var options = sp.GetRequiredService <IOptionsSnapshot <OpenIdConnectOptions> >().Get(OpenIdConnectDefaults.AuthenticationScheme);

        Assert.Equal(ti1.OpenIdConnectAuthority, options.Authority);
        Assert.Equal(ti1.OpenIdConnectClientId, options.ClientId);
        Assert.Equal(ti1.OpenIdConnectClientSecret, options.ClientSecret);
    }
コード例 #3
0
    public void ConfigurePerTenantAuthentication_UseCookieOptionsConvention()
    {
        var services = new ServiceCollection();

        services.AddOptions();
        services.AddAuthentication().AddCookie();
        services.AddMultiTenant <TestTenantInfo>()
        .WithPerTenantAuthentication();
        var sp = services.BuildServiceProvider();

        var ti1 = new TestTenantInfo
        {
            Id                     = "id1",
            Identifier             = "identifier1",
            CookieLoginPath        = "/path1",
            CookieLogoutPath       = "/path2",
            CookieAccessDeniedPath = "/path3"
        };

        var accessor = sp.GetRequiredService <IMultiTenantContextAccessor <TestTenantInfo> >();

        accessor.MultiTenantContext = new MultiTenantContext <TestTenantInfo> {
            TenantInfo = ti1
        };

        var options = sp.GetRequiredService <IOptionsSnapshot <CookieAuthenticationOptions> >().Get(CookieAuthenticationDefaults.AuthenticationScheme);

        Assert.Equal(ti1.CookieLoginPath, options.LoginPath);
        Assert.Equal(ti1.CookieLogoutPath, options.LogoutPath);
        Assert.Equal(ti1.CookieAccessDeniedPath, options.AccessDeniedPath);
    }