Ejemplo n.º 1
0
        public static void SetSigningProvider(HttpContext httpContext, OAuthRequestContext context)
        {
            /*
             * Check there is a signing provider for the signature method
             */
            ISigningProvider signingProvider = ServiceProviderContext.GetSigningProvider(context.Parameters.SignatureMethod);

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Double check the signing provider declares that it can handle the signature method
            if (!signingProvider.SignatureMethod.Equals(context.Parameters.SignatureMethod))
            {
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Ask the signing provider to check the request for pre-conditions
            if (!signingProvider.CheckRequest(httpContext.Request))
            {
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            context.SigningProvider = signingProvider;
        }
Ejemplo n.º 2
0
        protected virtual void SignParameters(Uri requestUri, string httpMethod, OAuthParameters authParameters, IToken token)
        {
            // Check there is a signing provider for the signature method
            ISigningProvider signingProvider = this.Service.ComponentLocator.GetInstance <ISigningProvider>(Constants.SigningProviderIdPrefix + this.Service.SignatureMethod);

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Double check the signing provider declares that it can handle the signature method
            if (!signingProvider.SignatureMethod.Equals(this.Service.SignatureMethod))
            {
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            authParameters.Sign(requestUri, httpMethod, this.Service.Consumer, token, signingProvider);
        }
Ejemplo n.º 3
0
        public void Test_NonexistentSigningProviderLookup()
        {
            ISigningProvider provider = ServiceProviderContext.GetSigningProvider("MADEUP");

            Assert.That(provider, Is.Null);
        }
Ejemplo n.º 4
0
        public void Sign(Uri requestUri, string httpMethod, IConsumer consumer, IToken token, ISigningProvider signingProvider)
        {
            if (token != null)
            {
                this.Token = token.Token;
            }

            OAuthParameters signingParameters = this.Clone();
            var             signingUri        = new UriBuilder(requestUri);

            // Normalize the request uri for signing
            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                // TODO: Will the parameters necessarily be Rfc3698 encoded here? If not, then Rfc3968.SplitAndDecode will throw FormatException
                signingParameters.AdditionalParameters.Add(Rfc3986.SplitAndDecode(requestUri.Query.Substring(1)));
                signingUri.Query = null;
            }

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            this.Signature = signingProvider.ComputeSignature(
                SignatureBase.Create(httpMethod, signingUri.Uri, signingParameters),
                consumer.Secret,
                (token != null && token.Secret != null) ? token.Secret : null);
        }
Ejemplo n.º 5
0
        public void Sign(Uri requestUri, string httpMethod, IConsumer consumer, IToken token, ISigningProvider signingProvider)
        {
            if (token != null)
                this.Token = token.Token;

            OAuthParameters signingParameters = this.Clone();
            var signingUri = new UriBuilder(requestUri);

            // Normalize the request uri for signing
            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                // TODO: Will the parameters necessarily be Rfc3698 encoded here? If not, then Rfc3968.SplitAndDecode will throw FormatException
                signingParameters.AdditionalParameters.Add(Rfc3986.SplitAndDecode(requestUri.Query.Substring(1)));
                signingUri.Query = null;
            }

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            this.Signature = signingProvider.ComputeSignature(
                SignatureBase.Create(httpMethod, signingUri.Uri, signingParameters),
                consumer.Secret,
                (token != null && token.Secret != null) ? token.Secret : null);
        }