Beispiel #1
0
 /// <summary>
 /// Over ride the to string method.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(UriUtility.FormatTokenForResponse(this));
 }
Beispiel #2
0
        /// <summary>
        /// Create a access 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 CreateAccessToken(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.ValidateAccessParametersAbsent(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.Token           = queryString[Parameters.OAuth_Token];
                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];
                context.Verifier        = queryString[Parameters.OAuth_Verifier];

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

                // Create the access token from the stores.
                IToken token = _oAuthProvider.ExchangeRequestTokenForAccessToken(context);
                return(UriUtility.FormatTokenForResponse(token));
            }
            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);
            }
        }