A token manager that only retains tokens in memory. Meant for SHORT TERM USE TOKENS ONLY.
A likely application of this class is for "Sign In With Twitter", where the user only signs in without providing any authorization to access Twitter APIs except to authenticate, since that access token is only useful once.
Inheritance: IConsumerTokenManager, IOpenIdOAuthTokenManager
 public Investigator()
 {
     logger = LogManager.GetLogger(typeof(Investigator));
     InMemoryTokenManager tokenManager = new InMemoryTokenManager(Constants.TwitterConsumerKey, Constants.TwitterConsumerSecret);
     tokenManager.StoreAccessToken(Constants.TwitterAccessToken, Constants.TwitterAccessSecret);
     consumer = new WebConsumer(UserModule.ServiceDescription, tokenManager);
 }
        /// <summary>
        /// Creates a 23 API service repository, that doesn't require further authentication. Account must be "privileged"
        /// </summary>
        /// <param name="consumerDomain">Domain name</param>
        /// <param name="consumerKey">Consumer key</param>
        /// <param name="consumerSecret">Consumer secret</param>
        /// <param name="accessToken">Access token</param>
        /// <param name="accessTokenSecret">Access token secret</param>
        public ApiProvider(string consumerDomain, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret)
        {
            // Save the authentication keys
            _consumerDomain = consumerDomain;

            _consumerKey = consumerKey;
            _consumerSecret = consumerSecret;

            // Open the OAuth consumer connection
            _oAuthProviderDescription.AccessTokenEndpoint = new MessageReceivingEndpoint("http://api.visualplatform.net/oauth/access_token", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.RequestTokenEndpoint = new MessageReceivingEndpoint("http://api.visualplatform.net/oauth/request_token", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.ProtocolVersion = ProtocolVersion.V10a;
            _oAuthProviderDescription.UserAuthorizationEndpoint = new MessageReceivingEndpoint("http://api.visualplatform.net/oauth/authorize", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() };

            _oAuthTokenManager = new InMemoryTokenManager(_consumerKey, _consumerSecret);

            _oAuthConsumer = new WebConsumer(_oAuthProviderDescription, _oAuthTokenManager);

            if (accessToken != null)
            {
                _accessToken = accessToken;
                _accessTokenSecret = accessTokenSecret;

                _oAuthTokenManager.ExpireRequestTokenAndStoreNewAccessToken(_consumerKey, "", _accessToken, _accessTokenSecret);
            }

            _oAuthConsumer.Channel.AssertBoundary();
        }
Exemple #3
0
        /// <summary>
        /// Creates a 23 API service repository, that doesn't require further authentication. Account must be "privileged"
        /// </summary>
        /// <param name="consumerDomain">Domain name</param>
        /// <param name="consumerKey">Consumer key</param>
        /// <param name="consumerSecret">Consumer secret</param>
        /// <param name="accessToken">Access token</param>
        /// <param name="accessTokenSecret">Access token secret</param>
        public ApiProvider(string consumerDomain, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret, bool httpSecure)
        {
            // Save the authentication keys
            _consumerDomain = consumerDomain;

            _consumerKey = consumerKey;
            _consumerSecret = consumerSecret;

            _httpSecure = httpSecure;

            string protocol = httpSecure ? "https://" : "http://";

            // Adjust timeout for requests to the domain to allow for large file uploads
            WebRequest.RegisterPrefix(protocol + _consumerDomain, TwentyThreeCreatorRequestCreator.TwentyThreeHttp);

            // Open the OAuth consumer connection
            _oAuthProviderDescription.AccessTokenEndpoint = new MessageReceivingEndpoint(protocol + "api.visualplatform.net/oauth/access_token", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.RequestTokenEndpoint = new MessageReceivingEndpoint(protocol + "api.visualplatform.net/oauth/request_token", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.ProtocolVersion = ProtocolVersion.V10a;
            _oAuthProviderDescription.UserAuthorizationEndpoint = new MessageReceivingEndpoint(protocol + "api.visualplatform.net/oauth/authorize", HttpDeliveryMethods.GetRequest);
            _oAuthProviderDescription.TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() };

            _oAuthTokenManager = new InMemoryTokenManager(_consumerKey, _consumerSecret);

            _oAuthConsumer = new WebConsumer(_oAuthProviderDescription, _oAuthTokenManager);

            if (accessToken != null)
            {
                _accessToken = accessToken;
                _accessTokenSecret = accessTokenSecret;

                _oAuthTokenManager.ExpireRequestTokenAndStoreNewAccessToken(_consumerKey, "", _accessToken, _accessTokenSecret);
            }

            _oAuthConsumer.Channel.AssertBoundary();
        }