public ActionResult Callback(string oauth_token, string oauth_token_secret, string oauth_verifier)
        {
            OAuthSession session = BuildSession();

            var requestToken = new TokenBase {TokenSecret = oauth_token_secret, Token = oauth_token};

            IToken accessToken = session.ExchangeRequestTokenForAccessToken(requestToken, "GET", oauth_verifier);

            lastAccessToken = accessToken;

            return View(accessToken);
        }
Exemplo n.º 2
0
        public void SaveAndReadTokenBase()
        {
            var token = new TokenBase ();
            token.Token = Guid.NewGuid ().ToString ();
            token.TokenSecret = Guid.NewGuid ().ToString ();

            using (var conn = connFactory.OpenDbConnection ()) {
                conn.Insert (token.ToDBAccessToken ());
            }
            using (var conn = connFactory.OpenDbConnection ()) {
                var dbtoken = conn.Select<DBAccessToken> ().First ();
                Assert.AreEqual (token.Token, dbtoken.Token);
                Assert.AreEqual (token.TokenSecret, dbtoken.Secret);
            }
        }
    public void TokenSecretNotIncludedInAuthorizationHeaderForPostRequestWithUseAuthorizationHeaders()
    {
      var session = new OAuthSession(new OAuthConsumerContext {ConsumerKey = "consumer", UseHeaderForOAuthParameters = true}, "http://localhost/request",
                                     "http://localhost/userauth", "http://localhost/access");

      var accessToken = new TokenBase {ConsumerKey = "consumer", Token = "token", TokenSecret = "secret"};

      RequestDescription description = session
        .Request(accessToken)
        .Post()
        .ForUrl("http://localhost/")
        .SignWithToken()
        .GetRequestDescription();

      Assert.False(description.Headers["Authorization"].Contains(Parameters.OAuth_Token_Secret));
    }
    public void TokenSecretNotIncludedInQueryParametersForGetRequest()
    {
      var session = new OAuthSession(new OAuthConsumerContext {ConsumerKey = "consumer"}, "http://localhost/request",
                                     "http://localhost/userauth", "http://localhost/access");

      var accessToken = new TokenBase {ConsumerKey = "consumer", Token = "token", TokenSecret = "secret"};

      RequestDescription description = session
        .Request(accessToken)
        .Get()
        .ForUrl("http://localhost/")
        .SignWithToken()
        .GetRequestDescription();

      Assert.False(description.Url.ToString().Contains(Parameters.OAuth_Token_Secret));
    }
Exemplo n.º 5
0
 public TokenPrincipal(IIdentity identity, string[] roles, TokenBase token)
   : base(identity, roles)
 {
   _token = token;
 }
		public void generate_request_with_raw_body_includes_body_hash()
		{
			var session = new OAuthSession(new OAuthConsumerContext {ConsumerKey = "consumer", UseHeaderForOAuthParameters = true}, "http://localhost/request", "http://localhost/userauth",
			                               "http://localhost/access");

			var accessToken = new TokenBase {ConsumerKey = "consumer", Token = "token", TokenSecret = "secret"};

			byte[] rawContents = Encoding.UTF8.GetBytes("Hello World!");

			IConsumerRequest content = session
				.EnableOAuthRequestBodyHashes()
				.Request(accessToken)
				.Post()
				.ForUrl("http://localhost/resource")
				.WithRawContent(rawContents);

			RequestDescription description = content.GetRequestDescription();

			Assert.Equal(rawContents, description.RawBody);

			Assert.Contains("oauth_body_hash=\"Lve95gjOVATpfV8EL5X4nxwjKHE%3D\"", description.Headers[Parameters.OAuth_Authorization_Header]);
		}