Exemplo n.º 1
0
        public async Task <bool> ValidateAsync(IDictionary <string, string> decodedClaims)
        {
            if (decodedClaims == null)
            {
                throw new ArgumentNullException(nameof(decodedClaims));
            }

            if (!decodedClaims.ContainsKey("exp") || !decodedClaims.ContainsKey("access_token"))
            {
                return(false);
            }
            // check exp max. 3 hrs

            var maxExpiry = _DateTimeProvider.Snapshot.AddHours(_IccPortalConfig.ClaimLifetimeHours).ToUnixTimeU64();

            if (!ulong.TryParse(decodedClaims["exp"], out var tokenExpiry))
            {
                return(false);
            }

            if (tokenExpiry > maxExpiry)
            {
                _Logger.WriteTokenExpTooLong(_IccPortalConfig.ClaimLifetimeHours.ToString());
                return(false);
            }

            return(await _TheIdentityHubService.VerifyTokenAsync(decodedClaims["access_token"]));
        }
        public void VerifyTokenShouldReturnTrueOnValidToken()
        {
            var validToken = "valid_access_token";

            _Server.Reset();
            _Server.Given(
                Request.Create()
                .WithHeader("Authorization", "Bearer " + validToken)
                .WithPath("/ggdghornl_test/oauth2/v1/verify").UsingGet()
                )
            .RespondWith(
                Response.Create()
                .WithStatusCode(200)
                .WithHeader("Content-Type", "application/json")
                .WithBody("{\"audience\":1234}")
                );

            Assert.True(_TheIdentityHubService.VerifyTokenAsync(validToken).Result);
        }
        public async Task <bool> ValidateAsync(IDictionary <string, string> decodedClaims)
        {
            if (decodedClaims == null)
            {
                throw new ArgumentNullException(nameof(decodedClaims));
            }

            if (!decodedClaims.ContainsKey("access_token"))
            {
                return(false);
            }

            if (decodedClaims["access_token"] == TestAccessToken)
            {
                _logger.WriteTestJwtUsed();
                return(true);
            }

            return(await _theIdentityHubService.VerifyTokenAsync(decodedClaims["access_token"]));
        }