public void GoogleConsumer()
        {
            X509Certificate2 certificate = TestCertificates.OAuthTestCertificate();

            string requestUrl       = "https://www.google.com/accounts/OAuthGetRequestToken";
            string userAuthorizeUrl = "https://www.google.com/accounts/accounts/OAuthAuthorizeToken";
            string accessUrl        = "https://www.google.com/accounts/OAuthGetAccessToken";
            string callBackUrl      = "http://www.mysite.com/callback";

            var consumerContext = new OAuthConsumerContext
            {
                ConsumerKey     = "weitu.googlepages.com",
                SignatureMethod = SignatureMethod.RsaSha1,
                Key             = certificate.PrivateKey
            };

            var session = new OAuthSession(consumerContext, requestUrl, userAuthorizeUrl, accessUrl)
                          .WithQueryParameters(new { scope = "http://www.google.com/m8/feeds" });

            // get a request token from the provider
            IToken requestToken = session.GetRequestToken();

            // generate a user authorize url for this token (which you can use in a redirect from the current site)
            string authorizationLink = session.GetUserAuthorizationUrlForToken(requestToken, callBackUrl);

            // exchange a request token for an access token
            IToken accessToken = session.ExchangeRequestTokenForAccessToken(requestToken);

            // make a request for a protected resource
            string responseText = session.Request().Get().ForUrl("http://www.google.com/m8/feeds/contacts/default/base").ToString();
        }
Exemple #2
0
 private OAuthConsumer CreateConsumer(string signatureMethod)
 {
     return(new OAuthConsumer("http://localhost/requesttoken.rails", "http://localhost/accesstoken.rails")
     {
         SignatureMethod = signatureMethod,
         ConsumerKey = "key",
         ConsumerSecret = "secret",
         Key = TestCertificates.OAuthTestCertificate().PrivateKey
     });
 }
 public OAuthConsumer CreateConsumer(string signatureMethod)
 {
     return(new OAuthConsumer(GetUriForAction("RequestToken"), GetUriForAction("AccessToken"))
     {
         ConsumerKey = "key",
         ConsumerSecret = "secret",
         Key = TestCertificates.OAuthTestCertificate().PrivateKey,
         SignatureMethod = signatureMethod
     });
 }
        static IOAuthSession CreateConsumer(string signatureMethod)
        {
            var consumerContext = new OAuthConsumerContext
            {
                SignatureMethod = signatureMethod,
                ConsumerKey     = "key",
                ConsumerSecret  = "secret",
                Key             = TestCertificates.OAuthTestCertificate().PrivateKey
            };

            var session = new OAuthSession(consumerContext, "http://localhost/oauth/requesttoken.rails",
                                           "http://localhost/oauth/userauhtorize.rails",
                                           "http://localhost/oauth/accesstoken.rails");

            return(session);
        }
Exemple #5
0
    protected IOAuthSession CreateSession()
    {
      string callBackUrl = "http://localhost:" + HttpContext.Current.Request.Url.Port + "/Callback.aspx";

      var consumerContext = new OAuthConsumerContext
        {
          ConsumerKey = "key",
          ConsumerSecret = "secret",
          Key = TestCertificates.OAuthTestCertificate().PrivateKey
        };

      return new OAuthSession(consumerContext,
                                     Settings.Default.RequestTokenUrl,
                                     Settings.Default.UserAuthorizationUrl,
                                     Settings.Default.AccessTokenUrl,
                                     callBackUrl).RequiresCallbackConfirmation();      
    }
        public void RsaSha1SignatureMethodFetchesCertificate()
        {
            var repository = new MockRepository();

            var consumerStore = repository.DynamicMock <IConsumerStore>();
            var signer        = repository.StrictMock <IOAuthContextSigner>();

            var context = new OAuthContext {
                ConsumerKey = "key", SignatureMethod = SignatureMethod.RsaSha1
            };

            using (repository.Record())
            {
                Expect.Call(consumerStore.GetConsumerPublicKey(context)).Return(
                    TestCertificates.OAuthTestCertificate().PublicKey.Key);
                Expect.Call(signer.ValidateSignature(null, null)).IgnoreArguments().Return(true);
            }
            using (repository.Playback())
            {
                var inspector = new SignatureValidationInspector(consumerStore, signer);
                inspector.InspectContext(ProviderPhase.GrantRequestToken, context);
            }
        }
Exemple #7
0
 public System.Security.Cryptography.AsymmetricAlgorithm GetConsumerPublicKey(IConsumer consumer)
 {
     return(TestCertificates.OAuthTestCertificate().PublicKey.Key);
 }
Exemple #8
0
 public X509Certificate2 GetConsumerCertificate(IConsumer consumer)
 {
   return TestCertificates.OAuthTestCertificate();
 }
 public AsymmetricAlgorithm GetConsumerPublicKey(IConsumer consumer)
 {
     return(TestCertificates.OAuthTestCertificate().PublicKey.Key);
 }