Esempio n. 1
0
        public void RequestTokenWithCallbackDoesNotThrowException()
        {
            IOAuthSession session = CreateConsumer(SignatureMethod.PlainText);
            IOAuthContext context = session.BuildRequestTokenContext("GET").Context;

            provider.GrantRequestToken(context);
        }
Esempio n. 2
0
        public void RequestTokenWithHmacSha1()
        {
            IOAuthSession session = CreateConsumer(SignatureMethod.HmacSha1);
            IOAuthContext context = session.BuildRequestTokenContext("GET").Context;
            IToken        token   = provider.GrantRequestToken(context);

            Assert.Equal("requestkey", token.Token);
            Assert.Equal("requestsecret", token.TokenSecret);
        }
Esempio n. 3
0
        public void RequestTokenWithHmacSha1()
        {
            OAuthConsumer consumer = CreateConsumer(SignatureMethod.HmacSha1);
            OAuthContext  context  = consumer.BuildRequestTokenContext(null);
            TokenBase     token    = provider.GrantRequestToken(context);

            Assert.AreEqual("requestkey", token.Token);
            Assert.AreEqual("requestsecret", token.TokenSecret);
        }
Esempio n. 4
0
        /// <summary>
        /// Create a request token from the request.
        /// </summary>
        /// <param name="rawUri">A System.Uri object containing information regarding the URL of the current request.</param>
        /// <param name="queryString">The collection of HTTP query string variables.</param>
        /// <param name="form">The collection of form variables.</param>
        /// <param name="headers">The collection of HTTP headers.</param>
        /// <param name="cookies">The collection of cookies sent by the client.</param>
        /// <returns>The token if successful; else null.</returns>
        public string CreateRequestToken(Uri rawUri, NameValueCollection queryString,
                                         NameValueCollection form, NameValueCollection headers, HttpCookieCollection cookies)
        {
            try
            {
                // Make sure that all the passed parameters are valid.
                if (rawUri == null)
                {
                    throw new ArgumentNullException("rawUri");
                }
                if (queryString == null)
                {
                    throw new ArgumentNullException("queryString");
                }
                if (form == null)
                {
                    throw new ArgumentNullException("form");
                }
                if (headers == null)
                {
                    throw new ArgumentNullException("headers");
                }
                if (cookies == null)
                {
                    throw new ArgumentNullException("cookies");
                }

                // Make sure that all the maditory OAuth parameters
                // have been passed to the provider from the consumer
                OAuthProblemReport validate = new OAuthProblemReport(queryString);
                validate.ValidateRequestParametersAbsent(queryString);
                string validationError = validate.ToString();

                // If any of the maditory OAuth parameters are missing.
                if (!String.IsNullOrEmpty(validationError))
                {
                    throw new OAuthException(OAuthProblemParameters.ParameterAbsent, "Absent Parameters", new Exception(validationError));
                }

                // Create an assign each manditory parameter.
                IOAuthContext context = new OAuthContextProvider();
                context.RawUri                = rawUri;
                context.RequestMethod         = "GET";
                context.Headers               = headers;
                context.QueryParameters       = queryString;
                context.FormEncodedParameters = form;
                context.CallbackUrl           = queryString[Parameters.OAuth_Callback];
                context.Nonce           = queryString[Parameters.OAuth_Nonce];
                context.ConsumerKey     = queryString[Parameters.OAuth_Consumer_Key];
                context.SignatureMethod = queryString[Parameters.OAuth_Signature_Method];
                context.Timestamp       = queryString[Parameters.OAuth_Timestamp];
                context.Signature       = queryString[Parameters.OAuth_Signature];

                // Assign each optional parameter
                GetOptionalRequestParameters(context, queryString);

                // Create the request token from the stores.
                IToken       token        = _oAuthProvider.GrantRequestToken(context);
                RequestToken requestToken = new RequestToken()
                {
                    Token         = token.Token,
                    TokenSecret   = token.TokenSecret,
                    ConsumerKey   = token.ConsumerKey,
                    CallbackUrl   = context.CallbackUrl,
                    SessionHandle = token.SessionHandle,
                    Realm         = token.Realm
                };

                // Return the request token string.
                return(requestToken.ToString());
            }
            catch (OAuthException aex)
            {
                // Get the current token errors.
                _tokenError = aex.Report.ToString();
                return(null);
            }
            catch (Exception ex)
            {
                // Transform the execption.
                OAuthException OAuthException =
                    new OAuthException(OAuthProblemParameters.ParameterRejected, ex.Message, ex);

                // Get the current token errors.
                _tokenError = OAuthException.Report.ToString();
                return(null);
            }
        }
        public TokenBase GrantRequestToken(IRequest request)
        {
            OAuthContext context = _contextFactory.FromMonoRailRequest(request);

            return(_provider.GrantRequestToken(context));
        }