예제 #1
0
    /// <inheritdoc />
    public async Task <string> StoreAsync(AuthenticationTicket ticket)
    {
        ArgumentNullException.ThrowIfNull(ticket);

        ticket.SetIssuer(await _issuerNameService.GetCurrentAsync());

        var key = CryptoRandom.CreateUniqueId(format: CryptoRandom.OutputFormat.Hex);

        _logger.LogDebug("Creating entry in store for AuthenticationTicket, key {key}, with expiration: {expiration}", key, ticket.GetExpiration());

        var session = new ServerSideSession
        {
            Key         = key,
            Scheme      = ticket.AuthenticationScheme,
            Created     = ticket.GetIssued(),
            Renewed     = ticket.GetIssued(),
            Expires     = ticket.GetExpiration(),
            SubjectId   = ticket.GetSubjectId(),
            SessionId   = ticket.GetSessionId(),
            DisplayName = ticket.GetDisplayName(_options.ServerSideSessions.UserDisplayNameClaimType),
            Ticket      = ticket.Serialize(_protector)
        };

        await _store.CreateSessionAsync(session);

        return(key);
    }