Ejemplo n.º 1
0
        /// <summary>
        /// Creates a message handler that signs outbound requests with a previously obtained authorization.
        /// </summary>
        /// <param name="accessToken">The access token to authorize outbound HTTP requests with.</param>
        /// <param name="innerHandler">The inner handler that actually sends the HTTP message on the network.</param>
        /// <returns>
        /// A message handler.
        /// </returns>
        /// <remarks>
        /// Overrides of this method may allow various derived types of handlers to be returned,
        /// enabling consumers that use RSA or other signing methods.
        /// </remarks>
        public virtual OAuth1HttpMessageHandlerBase CreateMessageHandler(AccessToken accessToken = default(AccessToken), HttpMessageHandler innerHandler = null)
        {
            Verify.Operation(this.ConsumerKey != null, Strings.RequiredPropertyNotYetPreset, "ConsumerKey");

            innerHandler = innerHandler ?? this.HostFactories.CreateHttpMessageHandler();
            OAuth1HttpMessageHandlerBase handler;

            if (this.ConsumerCertificate != null)
            {
                handler = new OAuth1RsaSha1HttpMessageHandler(innerHandler)
                {
                    SigningCertificate = this.ConsumerCertificate,
                };
            }
            else
            {
                handler = new OAuth1HmacSha1HttpMessageHandler(innerHandler);
            }

            handler.ConsumerKey       = this.ConsumerKey;
            handler.ConsumerSecret    = this.ConsumerSecret;
            handler.AccessToken       = accessToken.Token;
            handler.AccessTokenSecret = accessToken.Secret;

            return(handler);
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Creates a message handler that signs outbound requests with a previously obtained authorization.
		/// </summary>
		/// <param name="accessToken">The access token to authorize outbound HTTP requests with.</param>
		/// <param name="innerHandler">The inner handler that actually sends the HTTP message on the network.</param>
		/// <returns>
		/// A message handler.
		/// </returns>
		/// <remarks>
		/// Overrides of this method may allow various derived types of handlers to be returned,
		/// enabling consumers that use RSA or other signing methods.
		/// </remarks>
		public virtual OAuth1HttpMessageHandlerBase CreateMessageHandler(AccessToken accessToken = default(AccessToken), HttpMessageHandler innerHandler = null) {
			Verify.Operation(this.ConsumerKey != null, Strings.RequiredPropertyNotYetPreset, "ConsumerKey");

			innerHandler = innerHandler ?? this.HostFactories.CreateHttpMessageHandler();
			OAuth1HttpMessageHandlerBase handler;
			if (this.ConsumerCertificate != null) {
				handler = new OAuth1RsaSha1HttpMessageHandler(innerHandler) {
					SigningCertificate = this.ConsumerCertificate,
				};
			} else {
				handler = new OAuth1HmacSha1HttpMessageHandler(innerHandler);
			}

			handler.ConsumerKey = this.ConsumerKey;
			handler.ConsumerSecret = this.ConsumerSecret;
			handler.AccessToken = accessToken.Token;
			handler.AccessTokenSecret = accessToken.Secret;

			return handler;
		}