public void AccessProtectedResource() { IOAuthSession session = CreateConsumer(SignatureMethod.RsaSha1); session.AccessToken = new TokenBase { ConsumerKey = "key", Token = "accesskey", TokenSecret = "accesssecret" }; IOAuthContext context = session.Request().Get().ForUrl("http://localhost/protected.rails").SignWithToken().Context; context.TokenSecret = null; provider.AccessProtectedResourceRequest(context); }
/// <summary> /// Verify that the request is valid. /// </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> /// <returns>The token if successful; else null.</returns> public bool VerifyAuthorisation(Uri rawUri, NameValueCollection queryString, NameValueCollection form, NameValueCollection headers) { 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"); } // Make sure that all the maditory OAuth parameters // have been passed to the provider from the consumer OAuthProblemReport validate = new OAuthProblemReport(queryString); validate.ValidateResourceParametersAbsent(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.ConsumerKey = queryString[Parameters.OAuth_Consumer_Key]; // Assign each optional parameter GetOptionalRequestParameters(context, queryString); // Access protected resource; throws exception if access rejected. _oAuthProvider.AccessProtectedResourceRequest(context); // Return true verify. return(true); } catch (OAuthException aex) { // Get the current token errors. _tokenError = aex.Report.ToString(); return(false); } 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(false); } }