/// <summary>
        /// 保存刷新Token信息
        /// </summary>
        /// <param name="tokenInfo">Token信息</param>
        /// <returns></returns>
        public async virtual Task <bool> SaveToken(RefreshTokenInfo tokenInfo)
        {
            TClientRefreshToken token = new TClientRefreshToken()
            {
                Value           = tokenInfo.Value,
                ProtectedTicket = tokenInfo.ProtectedTicket,
                IssuedUtc       = tokenInfo.IssuedUtc,
                ExpiresUtc      = tokenInfo.ExpiresUtc
            };
            TClient client = (await ClientRepository.GetByPredicateAsync(m => m.ClientId == tokenInfo.ClientId)).FirstOrDefault();

            if (client == null)
            {
                return(false);
            }
            token.Client = client;
            TUser user = (await UserRepository.GetByPredicateAsync(m => m.UserName == tokenInfo.UserName)).FirstOrDefault();

            if (user == null)
            {
                return(false);
            }
            token.User = user;
            int result = await ClientRefreshTokenRepository.InsertAsync(token);

            return(result > 0);
        }
Пример #2
0
        public override async Task <bool> SaveToken(RefreshTokenInfo tokenInfo)
        {
            int result = 0;

            try
            {
                OAuthClientRefreshToken token = new OAuthClientRefreshToken()
                {
                    Value           = tokenInfo.Value,
                    ProtectedTicket = tokenInfo.ProtectedTicket,
                    IssuedUtc       = tokenInfo.IssuedUtc,
                    ExpiresUtc      = tokenInfo.ExpiresUtc
                };
                try
                {
                    ClientRepository.UnitOfWork.BeginTransaction();
                    var client = ClientRepository.TrackEntities.Where(m => m.ClientId == tokenInfo.ClientId).FirstOrDefault();
                    ClientRepository.UnitOfWork.Commit();
                    if (client == null)
                    {
                        return(false);
                    }
                    token.Client = client;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                UserRepository.UnitOfWork.BeginTransaction();
                User user = UserRepository.TrackEntities.Where(m => m.UserName == tokenInfo.UserName).FirstOrDefault();
                UserRepository.UnitOfWork.Commit();
                //User user = await UserManager.FindByNameAsync(tokenInfo.UserName);
                //User user = await userStore.FindByNameAsync(tokenInfo.UserName);
                if (user == null)
                {
                    return(false);
                }
                token.User = user;
                ClientRefreshTokenRepository.UnitOfWork.BeginTransaction();
                result = await ClientRefreshTokenRepository.InsertAsync(token);

                ClientRefreshTokenRepository.UnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                Logger.Error("OAuthClientRefreshTokenStore.SaveToken错误:" + ex.ToString());
            }


            return(result > 0);
        }