Ejemplo n.º 1
0
 /// <summary>	Searches for the first identity resources by scope asynchronous. </summary>
 /// <param name="scopeNames">	List of names of the scopes. </param>
 /// <returns>	The found identity resources by scope asynchronous. </returns>
 public Task <IEnumerable <IdentityResource> > FindIdentityResourcesByScopeAsync(IEnumerable <string> scopeNames)
 {
     return(Task <IEnumerable <IdentityResource> > .Factory.StartNew(() =>
     {
         using (var uow = _dataService.StartUnitOfWork())
         {
             var entities = uow.IdentityResourceRepository.GetByScopeNamesCompound(scopeNames);
             return FromCompoundEntities(entities);
         }
     }));
 }
        /// <summary>	Searches for the first client by identifier asynchronous. </summary>
        /// <param name="clientId">	Identifier for the client. </param>
        /// <returns>	The found client by identifier asynchronous. </returns>
        public Task <Client> FindClientByIdAsync(string clientId)
        {
            using (var uow = _dataService.StartUnitOfWork())
            {
                var entity = uow.ClientRepository.GetCompoundByClientId(clientId);
                if (entity == null)
                {
                    return(Task.FromResult((Client)null));
                }

                var client = new Client
                {
                    ClientId                         = entity.Client.ClientId,
                    ClientName                       = entity.Client.Name,
                    ClientSecrets                    = new List <Secret>(new[] { new Secret(entity.Client.Secret.Sha256()) }),
                    AllowedGrantTypes                = entity.Client.GrantTypes?.Split(','),
                    AllowedScopes                    = entity.Scopes.Select(s => s.Name).ToList(),
                    RedirectUris                     = new List <string>(GetUrisSplit(entity.Client.RedirectUri)),
                    PostLogoutRedirectUris           = new List <string>(GetUrisSplit(entity.Client.PostLogoutUri)),
                    AllowOfflineAccess               = entity.Client.AllowOfflineAccess,
                    AlwaysIncludeUserClaimsInIdToken = true,
                    AlwaysSendClientClaims           = false,
                    Claims = entity.ClientClaims
                             .Select(claimEntity => new Claim(claimEntity.ClaimType, claimEntity.ClaimValue))
                             .ToList()
                };

                return(Task.FromResult(client));
            }
        }
 /// <summary>	Stores the asynchronous. </summary>
 /// <param name="grant">	The grant. </param>
 /// <returns>	A Task. </returns>
 public Task StoreAsync(PersistedGrant grant)
 {
     return(Task.Factory.StartNew(() =>
     {
         using (var uow = _dataService.StartUnitOfWork())
         {
             var entity = new GrantEntity
             {
                 GrantKey = grant.Key,
                 ClientId = grant.ClientId,
                 CreationTime = grant.CreationTime,
                 Data = grant.Data,
                 Expiration = grant.Expiration,
                 SubjectId = grant.SubjectId,
                 Type = grant.Type
             };
             uow.GrantRepository.Add(entity);
             uow.Commit();
         }
     }));
 }