private static IJwtParser GetParser(byte[] key)
        {
            IJwtParser parser = new DefaultJwtParser(Serializers.Create().JsonNetSerializer().Build());
            parser.SetSigningKey(key);

            return parser;
        }
Esempio n. 2
0
        public void When_decoding(IDictionary<string, object> expectedPayload, string signingKey, string jwt)
        {
            IJwtParser parser = new DefaultJwtParser(Serializers.Create().JsonNetSerializer().Build());

            var signingKeyBytes = Encoding.UTF8.GetBytes(signingKey);
            var decoded = parser
                .SetSigningKey(signingKeyBytes)
                .Parse(jwt);

            decoded.Body.ToDictionary().ShouldBe(expectedPayload);
        }
Esempio n. 3
0
        public void When_verifying(IDictionary<string, object> ignored, string signingKey, string jwt)
        {
            IJwtParser parser = new DefaultJwtParser(Serializers.Create().JsonNetSerializer().Build());

            var signingKeyBytes = Encoding.UTF8.GetBytes(signingKey);
            var decoded = parser
                .SetSigningKey(signingKeyBytes)
                .Parse(jwt);

            var validator = new JwtSignatureValidator(signingKeyBytes);

            validator.IsValid(decoded).ShouldBeTrue();
        }
        IAccountResult IIdSiteSyncCallbackHandler.GetAccountResult()
        {
            var signingKeyBytes = Encoding.UTF8.GetBytes(
                this.internalDataStore.ApiKey.GetSecret());

            IJwtParser parser = new DefaultJwtParser(this.internalDataStore.Serializer);
            var jwt = parser
                .SetSigningKey(signingKeyBytes)
                .Parse(this.jwtResponse);

            HandlerShared.ThrowIfRequiredParametersMissing(jwt.Body);

            string apiKeyFromJwt = null;
            if (HandlerShared.IsError(jwt.Body))
            {
                jwt.Header.TryGetValueAsString(JwtHeaderParameters.KeyId, out apiKeyFromJwt);
            }
            else
            {
                apiKeyFromJwt = (string)jwt.Body.GetClaim(DefaultJwtClaims.Audience);
            }

            HandlerShared.ThrowIfJwtSignatureInvalid(apiKeyFromJwt, this.internalDataStore.ApiKey, jwt);
            HandlerShared.ThrowIfJwtIsExpired(jwt.Body);

            HandlerShared.IfErrorThrowIdSiteException(jwt.Body);

            if (!this.nonceStore.IsAsynchronousSupported || this.syncNonceStore == null)
            {
                throw new ApplicationException("The current nonce store does not support synchronous operations.");
            }

            var responseNonce = (string)jwt.Body.GetClaim(IdSiteClaims.ResponseId);
            this.ThrowIfNonceIsAlreadyUsed(responseNonce);
            this.syncNonceStore.PutNonce(responseNonce);

            HandlerShared.ThrowIfSubjectIsMissing(jwt.Body);

            var accountResult = HandlerShared.CreateAccountResult(jwt.Body, this.internalDataStore);
            var resultStatus = HandlerShared.GetResultStatus(jwt.Body);

            if (this.resultListener != null)
            {
                this.DispatchResponseStatus(resultStatus, accountResult);
            }

            return accountResult;
        }