Create() public static method

Makes an instance of OAuth2Tokens.
public static Create ( string consumerKey, string consumerSecret, string bearer ) : OAuth2Token
consumerKey string The consumer key.
consumerSecret string The consumer secret.
bearer string The bearer token.
return OAuth2Token
Beispiel #1
0
 /// <summary>
 /// Gets the OAuth 2 Bearer Token as an asynchronous operation.
 /// </summary>
 /// <param name="consumerKey">The consumer key.</param>
 /// <param name="consumerSecret">The consumer secret.</param>
 /// <param name="options">The connection options for the request.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// <para>The task object representing the asynchronous operation.</para>
 /// <para>The Result property on the task object returns the tokens.</para>
 /// </returns>
 public static Task <OAuth2Token> GetTokenAsync(string consumerKey, string consumerSecret, ConnectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return
         (Request.HttpPostAsync(
              AccessTokenUrl,
              new Dictionary <string, object>()
     {
         { "grant_type", "client_credentials" }
     },
              CreateCredentials(consumerKey, consumerSecret),
              options,
              cancellationToken
              )
          .ResponseCallback(cancellationToken)
          .ContinueWith(
              t => InternalUtils.ReadResponse(t, s =>
     {
         var token = OAuth2Token.Create(
             consumerKey, consumerSecret,
             (string)JObject.Parse(s)["access_token"]
             );
         token.ConnectionOptions = options;
         return token;
     }, cancellationToken),
              cancellationToken
              ).Unwrap());
 }
Beispiel #2
0
 /// <summary>
 /// Gets the OAuth 2 Bearer Token.
 /// </summary>
 /// <param name="consumerKey">The consumer key.</param>
 /// <param name="consumerSecret">The consumer secret.</param>
 /// <param name="options">The connection options for the request.</param>
 /// <returns>The tokens.</returns>
 public static OAuth2Token GetToken(string consumerKey, string consumerSecret, ConnectionOptions options = null)
 {
     try
     {
         var token = from x in Request.HttpPost(
             AccessTokenUrl,
             new Dictionary <string, object>()
         {
             { "grant_type", "client_credentials" }
         },                                                                                           //  At this time, only client_credentials is allowed.
             CreateCredentials(consumerKey, consumerSecret),
             options).Use()
                     from y in new StreamReader(x.GetResponseStream()).Use()
                     select(string) JObject.Parse(y.ReadToEnd())["access_token"];
         var t = OAuth2Token.Create(consumerKey, consumerSecret, token);
         t.ConnectionOptions = options;
         return(t);
     }
     catch (WebException ex)
     {
         var tex = TwitterException.Create(ex);
         if (tex != null)
         {
             throw tex;
         }
         throw;
     }
 }
Beispiel #3
0
        /// <summary>
        /// Gets the OAuth 2 Bearer Token.
        /// </summary>
        /// <param name="consumerKey">Consumer key.</param>
        /// <param name="consumerSecret">Consumer secret.</param>
        /// <param name="proxy">Proxy information for the request.</param>
        /// <returns>The tokens.</returns>
        public static OAuth2Token GetToken(string consumerKey, string consumerSecret, IWebProxy proxy = null)
        {
            var token = from x in Request.HttpPost(
                AccessTokenUrl,
                new Dictionary <string, object>()
            {
                { "grant_type", "client_credentials" }
            },                                                                                          //  At this time, only client_credentials is allowed.
                CreateCredentials(consumerKey, consumerSecret),
                "CoreTweet",
                proxy,
                true).Use()
                        from y in new StreamReader(x).Use()
                        select(string) JObject.Parse(y.ReadToEnd())["access_token"];
            var t = OAuth2Token.Create(consumerKey, consumerSecret, token);

            t.Proxy = proxy;
            return(t);
        }