Beispiel #1
0
 /// <summary>
 /// Ctor.
 /// </summary>
 public DefaultSessionManagementService(
     IServerSideTicketService serverSideTicketService,
     IServerSideSessionStore serverSideSessionStore,
     IPersistedGrantStore persistedGrantStore,
     IBackChannelLogoutService backChannelLogoutService)
 {
     _serverSideTicketService  = serverSideTicketService;
     _serverSideSessionStore   = serverSideSessionStore;
     _persistedGrantStore      = persistedGrantStore;
     _backChannelLogoutService = backChannelLogoutService;
 }
Beispiel #2
0
    public ServerSideSessionTests()
    {
        _urls.Origin   = IdentityServerPipeline.BaseUrl;
        _urls.BasePath = "/";
        _pipeline.OnPostConfigureServices += s =>
        {
            s.AddSingleton <IServerUrls>(_urls);
            s.AddIdentityServerBuilder().AddServerSideSessions();
        };
        _pipeline.OnPostConfigure += app =>
        {
            _pipeline.Options.ServerSideSessions.RemoveExpiredSessionsFrequency = TimeSpan.FromMilliseconds(100);

            app.Map("/user", ep => {
                ep.Run(ctx =>
                {
                    if (ctx.User.Identity.IsAuthenticated)
                    {
                        ctx.Response.StatusCode = 200;
                    }
                    else
                    {
                        ctx.Response.StatusCode = 401;
                    }
                    return(Task.CompletedTask);
                });
            });
        };


        _pipeline.Users.Add(new TestUser
        {
            SubjectId = "bob",
            Username  = "******",
        });
        _pipeline.Users.Add(new TestUser
        {
            SubjectId = "alice",
            Username  = "******",
        });

        _pipeline.Clients.Add(new Client
        {
            ClientId            = "client",
            AllowedGrantTypes   = GrantTypes.Code,
            RequireClientSecret = false,
            RequireConsent      = false,
            RequirePkce         = false,
            AllowedScopes       = { "openid", "api" },
            AllowOfflineAccess  = true,
            CoordinateLifetimeWithUserSession = true,
            RefreshTokenUsage    = TokenUsage.ReUse,
            RedirectUris         = { "https://client/callback" },
            BackChannelLogoutUri = "https://client/bc-logout"
        });
        _pipeline.IdentityScopes.Add(new IdentityResources.OpenId());
        _pipeline.ApiScopes.Add(new ApiScope("api"));

        _pipeline.Initialize();

        _sessionStore      = _pipeline.Resolve <IServerSideSessionStore>();
        _ticketService     = _pipeline.Resolve <IServerSideTicketService>();
        _sessionMgmt       = _pipeline.Resolve <ISessionManagementService>();
        _grantStore        = _pipeline.Resolve <IPersistedGrantStore>();
        _refreshTokenStore = _pipeline.Resolve <IRefreshTokenStore>();
    }