public DataResult <bool> SavePersistedGrant(PersistedGrantModel grant)
        {
            var newGrant = new PersistedGrantEntity
            {
                Key            = grant.Key,
                Type           = grant.Type,
                CreationTime   = grant.CreationTime,
                ExpirationTime = grant.ExpirationTime,
                Data           = grant.Data
            };

            try
            {
                m_persistedGrantUoW.SavePersistedGrant(grant.User.Id, grant.Client.Name, newGrant);
                return(Success(true));
            }
            catch (NoResultException <UserEntity> e)
            {
                m_logger.LogWarning(e);
                return(Error <bool>(m_translator.Translate("invalid-user-id"), DataResultErrorCode.UserNotExistId));
            }
            catch (NoResultException <ClientEntity> e)
            {
                m_logger.LogWarning(e);
                return(Error <bool>(m_translator.Translate("invalid-client-id"), DataResultErrorCode.ClientNotExistId));
            }
            catch (DatabaseException e)
            {
                m_logger.LogWarning(e);
                return(Error <bool>(e.Message));
            }
        }
    public async Task StoreAsync(PersistedGrant grant)
    {
        var entity = new PersistedGrantEntity(grant);

        await using var connection = new MySqlConnection(_connectionString);
        await RemoveAsync(grant.Key);

        string sql = "insert into tbl_user_persistedgrant(`Key`,Type,SubjectId,ClientId,CreationTime,ConsumedTime,Expiration,Data,Description,SessionId) values " +
                     "(@Key,@Type,@SubjectId,@ClientId,@CreationTime,@ConsumedTime,@Expiration,@Data,@Description,@SessionId)";
        await connection.ExecuteAsync(sql, entity);
    }
Exemple #3
0
 private static PersistedGrant FromEntity(PersistedGrantEntity entity)
 {
     return(new ()
     {
         Key = entity.Id,
         Type = entity.Type,
         SubjectId = entity.SubjectId,
         SessionId = entity.SessionId,
         ClientId = entity.ClientId,
         Description = entity.Description,
         CreationTime = entity.CreateDate,
         Expiration = entity.ExpirationDate,
         ConsumedTime = entity.ConsumedDate,
         Data = entity.Data
     });
 }
        public async Task Persist_Grant_That_Will_Expire()
        {
            var ttl = 5; // 2 seconds

            _currentEntity = new PersistedGrantEntity
            {
                Key          = NewGuidS,
                ClientId     = NewGuidS,
                CreationTime = DateTime.UtcNow,
                Data         = NewGuidS,
                Expiration   = DateTime.UtcNow.AddSeconds(ttl),
                Type         = NewGuidS,
                TTL          = ttl
            };


            var response = await _persistedGrantCosmosStore.AddAsync(_currentEntity);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.CosmosOperationStatus.Should().Be(CosmosOperationStatus.Success);
        }
        public virtual void SavePersistedGrant(int userId, string grantClientId, PersistedGrantEntity newGrant)
        {
            var user = m_userRepository.FindById <UserEntity>(userId);

            if (user == null)
            {
                throw new NoResultException <UserEntity>();
            }

            var client = m_clientRepository.FindClientByName(grantClientId);

            if (client == null)
            {
                throw new NoResultException <ClientEntity>();
            }

            var persistedGrant = m_persistedGrantRepository.FindByKey(newGrant.Key);

            if (persistedGrant != null) //TODO Investigate performance of this
            {
                persistedGrant.Client         = client;
                persistedGrant.User           = user;
                persistedGrant.CreationTime   = newGrant.CreationTime;
                persistedGrant.ExpirationTime = newGrant.ExpirationTime;
                persistedGrant.Type           = newGrant.Type;
                persistedGrant.Data           = newGrant.Data;

                m_persistedGrantRepository.Save(persistedGrant);
            }
            else
            {
                newGrant.User   = user;
                newGrant.Client = client;

                m_persistedGrantRepository.Create(newGrant);
            }
        }
 public static void UpdateEntity(this PersistedGrant model, PersistedGrantEntity entity)
 {
     Mapper.Map(model, entity);
 }
 public static PersistedGrant ToModel(this PersistedGrantEntity entity)
 {
     return(entity == null ? null : Mapper.Map <PersistedGrant>(entity));
 }
Exemple #8
0
 public void Create(PersistedGrantEntity entity)
 {
     _db.PersistedGrants.Add(entity);
     _db.SaveChanges();
 }
Exemple #9
0
 public async Task remove_all_subjectid_clientid_type()
 {
     _currentRemoveAllEntityType = _currentManyEntities[0];
     await _persistedGrantStore.RemoveAllAsync(_currentRemoveAllEntityType.SubjectId, _currentRemoveAllEntityType.ClientId, _currentRemoveAllEntityType.Type);
 }