public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            try
            {
                var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

                var hashedTokenId = Utilities.GetHash(context.Token);
                using (IApplicationRepository rep = new ApplicationRepository())
                {
                    var refreshToken = await rep.RefreshTokens.FindAsync(hashedTokenId);

                    if (refreshToken != null)
                    {
                        //Get protectedTicket from refreshToken class
                        context.DeserializeTicket(refreshToken.ProtectedTicket);
                        var result = await rep.RefreshTokens.RemoveAsync(hashedTokenId);
                    }
                }

            }
            catch (Exception e)
            {

                throw e;
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");

            if (context.OwinContext.Response.Headers.Keys.Contains("Access-Control-Allow-Origin"))
            {
                context.OwinContext.Response.Headers["Access-Control-Allow-Origin"] = allowedOrigin;
            }
            else
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {allowedOrigin});
            }

            var hashedTokenId = TokenHelper.GetHash(context.Token);

            using (var _repo = new AuthRepository())
            {
                var refreshToken = await _repo.FindRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    var result = await _repo.RemoveRefreshToken(hashedTokenId);
                }
            }
        }
 public override void Receive(AuthenticationTokenReceiveContext context)
 {
     string value;
     if (_codes.TryRemove(context.Token, out value))
     {
         context.DeserializeTicket(value);
     }
 }
 private void ReceiveAuthenticationCode(AuthenticationTokenReceiveContext context)
 {
     string value;
     if (_authCodes.TryRemove(context.Token, out value))
     {
         context.DeserializeTicket(value);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 public override void Receive(AuthenticationTokenReceiveContext context)
 {
     string token;
     if (_refreshTokens.TryRemove(context.Token, out token))
     {
         context.DeserializeTicket(token);
     }
 }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            await Task.Run(() =>
            {
                context.DeserializeTicket(context.Token);
            });

            
        }
 /// <summary>
 /// 移除RefreshToken,在客户端使用RefreshToken请求新的AccessToken的时候自动调用
 /// </summary>
 /// <param name="context"></param>
 public async override Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     RefreshTokenInfo token = await _clientRefreshTokenStore.GetTokenInfo(context.Token);
     if (token == null)
     {
         return;
     }
     context.DeserializeTicket(token.ProtectedTicket);
     await _clientRefreshTokenStore.Remove(context.Token);
 }
        public void Receive(AuthenticationTokenReceiveContext context)
        {
            context.DeserializeTicket(context.Token);
            //var isUpdated = _usersRepository.IsRegisteredUserUpdated(context.Ticket.Identity.Claims.First(i => i.Type == ClaimTypes.NameIdentifier));

            /*f (isUpdated)
            {
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                context.Response.ReasonPhrase = Exceptions.UserDataChanged;
            }*/
        }
 public override void Receive(AuthenticationTokenReceiveContext context)
 {
     var container = context.OwinContext.GetAutofacLifetimeScope();
     var membershipService = container.Resolve<IAuthorizationService>();
     var hashedTokenId = VaBank.Common.Security.Hash.Compute(context.Token);
     var token = membershipService.RevokeToken(new IdentityQuery<string>(hashedTokenId));
     if (token != null)
     {
         context.DeserializeTicket(token.Value);
     }
     base.Receive(context);
 }
Example #10
0
    public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) {
      var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
      context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
      string hashedToken = PasswordHelper.HashToken(context.Token);

      var authenticationClient = new AuthenticationClient();
      var response = await authenticationClient.GetRefreshToken(new GetRefreshTokenRequest { HashedToken = hashedToken });
      if (response.RefreshToken != null) {
        context.DeserializeTicket(response.RefreshToken.ProtectedTicket);
        await authenticationClient.DeleteRefreshToken(new DeleteRefreshTokenRequest { HashedToken = hashedToken });
      }
    }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
            var hashedTokenId = AuthorizationHelpers.GetHash(context.Token);

            var refreshToken = await _userRepository.FindRefreshTokenAsync(hashedTokenId);
            if (refreshToken != null)
            {
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                await _userRepository.TryRemoveRefreshTokenAsync(hashedTokenId);
            }
        }
        public void Receive(AuthenticationTokenReceiveContext context)
        {
            var hashedTokenId = Helper.GetHash(context.Token);
            var appTokenService = mobSocialEngine.ActiveEngine.Resolve<IAppTokenService>();

            var appToken = appTokenService.FirstOrDefault(x => x.Guid == hashedTokenId);
            if (appToken != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(appToken.ProtectedTicket);
                appTokenService.Delete(appToken);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            string hashedTokenId = CommonMethod.GetHash(context.Token);

            var token = RedisHelp.GetObj<RefreshToken>(hashedTokenId);
            var user = RedisHelp.GetLoginUserCacheNotNull(int.Parse(token.ClientId));

            if (user != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(token.ProtectedTicket);
                bool flag = RedisHelp.ItemRemove(hashedTokenId);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var authClient = context.OwinContext.Get<AuthClient>("authClient");

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { authClient.AllowedOrigin });

            //TODO: get the refresh token
            var token = new RefreshToken(); 

            if (token != null)
            {
                context.DeserializeTicket(token.ProtectedTicket);

                //TODO: remove token when used
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = Helper.GetHash(context.Token);
            var refreshToken = await _authService.FindRefreshToken(hashedTokenId);

            if (refreshToken != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                await _authService.RemoveRefreshToken(hashedTokenId);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hasedTokenId = SharedServices.HashingService.GetHash(context.Token);

            var tokenObj = new BusinessLogic.Identity.RefreshTokens();
            var refreshToken = await tokenObj.GetByID(hasedTokenId);

            if (refreshToken != null)
            {
                context.DeserializeTicket(refreshToken.protectedTicket);
                var result = await tokenObj.Delete(hasedTokenId);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:AllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string tokenId = context.Token;

            var refreshToken = await _redisRepo.GetRefreshTokenAsync(tokenId);

            if (refreshToken != null)
            {
                context.DeserializeTicket(refreshToken.Token);
                var result = await _redisRepo.RemoveRefreshToken(tokenId, refreshToken.Subject);
            }
            
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            string hashedTokenId = context.Token.GetHash();

            using (AuthRepository _repo = new AuthRepository())
            {
                var refreshToken = await _repo.FindRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    var result = await _repo.RemoveRefreshToken(hashedTokenId);
                }
            }
        }
        public Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var AllowedOrigin = context.OwinContext.Get<string>(GenericNames.OWIN_CONTEXT_CORS);
            context.OwinContext.Response.Headers.Remove(GenericNames.OWIN_CONTEXT_CORS_HEADER);
            context.OwinContext.Response.Headers.Add(GenericNames.OWIN_CONTEXT_CORS_HEADER, new[] { AllowedOrigin });

            IDependencyScope Scope = context.OwinContext.Get<IDependencyScope>();
            IRefreshTokenRepository refreshTokenRepository = Scope.GetService(typeof(IRefreshTokenRepository)) as IRefreshTokenRepository;

            var refreshToken = refreshTokenRepository.GetUniq(x => x.Id == context.Token);
            if (refreshToken != null)
            {
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                refreshTokenRepository.Delete(refreshToken);
            }
            return Task.FromResult<object>(null);
        }
        public virtual async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            var hashedTokenId = context.Token.GenerateHash();

            await Task.Run(() => {

                var token = this._oauthStore.FindRefreshToken(hashedTokenId);
                if (token != null)
                {
                    context.DeserializeTicket(token.ProtectedTicket);
                    this._oauthStore.RemoveRefreshToken(hashedTokenId);
                }
            
            });
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            string hashedTokenId = Helper.GetHash(context.Token);

            using (var ctx = new ApplicationDbContext())
            {
                var refreshToken = await ctx.FindRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    var result = await ctx.RemoveRefreshToken(hashedTokenId);
                }
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            if (GetRefreshTokenProtectedTicketFunc == null || RemoveRefreshTokenFunc == null)
                throw new ArgumentNullException();

            var allowedOrigin = context.OwinContext.Get<string>(OAuthDefaults.OwinKeyAllowedOrigin);
            context.OwinContext.Response.Headers.Add(OAuthDefaults.HeaderKeyAllowedOrigin, new[] { allowedOrigin });

            string hashedTokenId = Helper.GetHash(context.Token);

            var protectedTicket = GetRefreshTokenProtectedTicketFunc(hashedTokenId);
            if (protectedTicket != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(protectedTicket);
                RemoveRefreshTokenFunc(hashedTokenId);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = context.Token.GetHashSHA256();

            using (AuthRepository repository = new AuthRepository())
            {
                var refreshToken = await repository.FindRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    await repository.RemoveRefreshToken(hashedTokenId);
                }
            }
        }
Example #24
0
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = CryptoHelper.GetHash(context.Token);


            var response = await _manager.FindByIdAsync(hashedTokenId);

            if (response.IsSuccessful)
            {
                var refreshToken = response.Result;
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                await _manager.Delete(hashedTokenId);
            }
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = Helper.GetHash(context.Token);

            
            var refreshToken = DataProvider.RefreshTokens.FirstOrDefault(o=>o.Id == hashedTokenId);

            if (refreshToken != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                DataProvider.RefreshTokens.Remove(refreshToken);
            }
            
        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = Helper.GetHash(context.Token);

            using (AutenticacionRepository _repo = new AutenticacionRepository())
            {
                var refreshToken = await _repo.BuscarRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.TicketProtegido);
                    var result = await _repo.RemoverRefreshToken(hashedTokenId);
                }
            }
        }
 public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     this.CurrentToken = context.Token;
     string allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
     context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new string[1]
     {
 allowedOrigin
     });
     string hashedTokenId = ApplicationOAuthProvider.GetSecretHash(context.Token);
     UnityContainer unityContainer = UnityConfig.GetConfiguredContainer() as UnityContainer;
     IRefreshTokenBll refreshTokenBll = UnityContainerExtensions.Resolve<IRefreshTokenBll>((IUnityContainer)unityContainer);
     RefreshToken refreshToken = await refreshTokenBll.GetOneRefreshToken(hashedTokenId);
     if (refreshToken != null)
     {
         context.DeserializeTicket(refreshToken.ProtectedTicket);
         int num = await refreshTokenBll.RemoveRefreshToken(hashedTokenId);
     }
     else
         await this.LogHistory(LoginType.RefreshToken, LoginStatus.InvalidRefreshToken, (string)null, (string)null, context.Token, (string)null, (string)null);
 }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            try
            {
                string hashedTokenId = Hash.Get(context.Token);

                using (AuthRepository _repo = new AuthRepository())
                {
                    var refreshToken = _repo.FindRefreshToken(hashedTokenId);

                    if (refreshToken != null)
                    {
                        context.DeserializeTicket(refreshToken.ProtectedTicket);
                        var result = await _repo.RemoveRefreshToken(hashedTokenId);
                    }
                }
            }
            catch (Exception ex)
            {
                Helper.ErroLogging.LogError(ex);
            }
        }
        public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {




            string hashedTokenId = HashingService.MakeHash(context.Token);

            RefreshTokenService _repo = new RefreshTokenService();

            RefreshToken refreshToken =  _repo.FindRefreshToken(hashedTokenId);

            if (refreshToken != null)
            {
                //Get protectedTicket from refreshToken class
                context.DeserializeTicket(refreshToken.ProtectedTicket);
                var result = _repo.RemoveRefreshToken(hashedTokenId);
            }

         

        }
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            var tokenId = context.Token;
            RefreshToken storedToken;
            repo.TryGetValue(tokenId, out storedToken);

            var allowedOrigins = context.OwinContext.Get<List<string>>("as:clientAllowedOrigins");
            context.OwinContext.Response.Headers.Add(
                "Access-Control-Allow-Origin", allowedOrigins.ToArray());

            await Task.Delay(2);
            if (DateTime.UtcNow > storedToken.ExpiresUtc)
            {
                //    context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                //    context.Response.ReasonPhrase = "The rtoken has expired";
                //    return;
                var a = 1;
            }
            context.DeserializeTicket(storedToken.ProtectedTicket);
            var aasd = context.Ticket;
            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            //repo.Remove(tokenId);
        }