/// <summary>
        /// This method is able to exchange the request token into an access token which can be used in
        /// sharpbox. It is necessary that the user validated the request via authorization url otherwise
        /// this call wil results in an unauthorized exception!
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="ConsumerKey"></param>
        /// <param name="ConsumerSecret"></param>
        /// <param name="DropBoxRequestToken"></param>
        /// <returns></returns>
        static public ICloudStorageAccessToken ExchangeDropBoxRequestTokenIntoAccessToken(DropBoxConfiguration configuration, String ConsumerKey, String ConsumerSecret, DropBoxRequestToken DropBoxRequestToken)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(ConsumerKey, ConsumerSecret);

            // build up the oauth session
            var serviceContext = new OAuthServiceContext(configuration.RequestTokenUrl.ToString(),
                                                         configuration.AuthorizationTokenUrl.ToString(), configuration.AuthorizationCallBack.ToString(),
                                                         configuration.AccessTokenUrl.ToString());

            // build the access token
            OAuthService svc         = new OAuthService();
            OAuthToken   accessToken = svc.GetAccessToken(serviceContext, consumerContext, DropBoxRequestToken.RealToken);

            if (accessToken == null)
            {
                throw new UnauthorizedAccessException();
            }

            // create the access token
            return(new DropBoxToken(accessToken,
                                    new DropBoxBaseTokenInformation()
            {
                ConsumerKey = ConsumerKey,
                ConsumerSecret = ConsumerSecret
            }));
        }
示例#2
0
        public OAuthToken GetRequestToken(OAuthServiceContext svcContext, OAuthConsumerContext conContext)
        {
            // generate the url
            String requestTokenUrl = OAuthUrlGenerator.GenerateRequestTokenUrl(svcContext.RequestTokenUrl, conContext);

            // get the token
            return(GetToken(requestTokenUrl));
        }
        public static GoogleDocsRequestToken GetGoogleDocsRequestToken(GoogleDocsConfiguration configuration, String consumerKey, String consumerSecret)
        {
            var consumerContext = new OAuthConsumerContext(consumerKey, consumerSecret);
            var serviceContext  = new OAuthServiceContext(GetRequestTokenUrl(configuration),
                                                          configuration.OAuthAuthorizeTokenUrl.ToString(),
                                                          configuration.AuthorizationCallBack.ToString(),
                                                          GetAccessTokenUrl(configuration, null));
            var service = new OAuthService();
            var token   = service.GetRequestToken(serviceContext, consumerContext);

            return(token != null ? new GoogleDocsRequestToken(token) : null);
        }
        /// <summary>
        /// This method retrieves a new request token from the dropbox server
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="ConsumerKey"></param>
        /// <param name="ConsumerSecret"></param>
        /// <returns></returns>
        static public DropBoxRequestToken GetDropBoxRequestToken(DropBoxConfiguration configuration, String ConsumerKey, String ConsumerSecret)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(ConsumerKey, ConsumerSecret);

            // build up the oauth session
            var serviceContext = new OAuthServiceContext(configuration.RequestTokenUrl.ToString(),
                                                         configuration.AuthorizationTokenUrl.ToString(), configuration.AuthorizationCallBack.ToString(),
                                                         configuration.AccessTokenUrl.ToString());

            // get a request token from the provider
            OAuthService svc = new OAuthService();

            return(new DropBoxRequestToken(svc.GetRequestToken(serviceContext, consumerContext)));
        }
        public static ICloudStorageAccessToken ExchangeGoogleDocsRequestTokenIntoAccessToken(GoogleDocsConfiguration configuration, String consumerKey, String consumerSecret, GoogleDocsRequestToken requestToken, String oAuthVerifier)
        {
            var consumerContext = new OAuthConsumerContext(consumerKey, consumerSecret);
            var serviceContext  = new OAuthServiceContext(configuration.OAuthGetRequestTokenUrl.ToString(),
                                                          configuration.OAuthAuthorizeTokenUrl.ToString(),
                                                          configuration.AuthorizationCallBack.ToString(),
                                                          GetAccessTokenUrl(configuration, oAuthVerifier));
            var service     = new OAuthService();
            var accessToken = service.GetAccessToken(serviceContext, consumerContext, requestToken.RealToken);

            if (accessToken == null)
            {
                throw new UnauthorizedAccessException();
            }
            return(new GoogleDocsToken(accessToken, consumerKey, consumerSecret));
        }
        /// <summary>
        /// This method offers the mobile login api of dropbox for users who are migrating from version 0 of the
        /// dropbox API because version 1 supports token based logins only
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="appkey"></param>
        /// <param name="appsecret"></param>
        /// <returns></returns>
        static public ICloudStorageAccessToken LoginWithMobileAPI(String username, String password, String appkey, String appsecret)
        {
            // get the configuration
            DropBoxConfiguration configuration = DropBoxConfiguration.GetStandardConfiguration();

            // build the consumer context
            var consumerContext = new OAuthConsumerContext(appkey, appsecret);

            // build up the oauth session
            var serviceContext = new OAuthServiceContext(configuration.RequestTokenUrl.ToString(),
                                                         configuration.AuthorizationTokenUrl.ToString(), configuration.AuthorizationCallBack.ToString(),
                                                         configuration.AccessTokenUrl.ToString());

            // get a request token from the provider
            OAuthService svc = new OAuthService();
            var          oAuthRequestToken = svc.GetRequestToken(serviceContext, consumerContext);

            if (oAuthRequestToken == null)
            {
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidConsumerKeySecret);
            }
            DropBoxToken DropBoxRequestToken = new DropBoxToken(oAuthRequestToken, new DropBoxBaseTokenInformation()
            {
                ConsumerKey = appkey, ConsumerSecret = appsecret
            });

            // generate the dropbox service
            DropBoxStorageProviderService service = new DropBoxStorageProviderService();

            // build up a request Token Session
            var requestSession = new DropBoxStorageProviderSession(DropBoxRequestToken, configuration, consumerContext, service);

            // build up the parameters
            var param = new Dictionary <String, String>
            {
                { "email", username },
                { "password", password }
            };

            // call the mobile login api
            String result = "";

            try
            {
                int code;
                result = DropBoxRequestParser.RequestResourceByUrl(DropBoxMobileLogin, param, service, requestSession, out code);
                if (result.Length == 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }

#if MONOTOUCH || WINDOWS_PHONE || MONODROID
            catch (Exception ex)
            {
                if (ex is UnauthorizedAccessException)
                {
                    throw ex;
                }
                else
                {
                    throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService, ex);
                }
            }
#else
            catch (System.Web.HttpException netex)
            {
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorCouldNotContactStorageService, netex);
            }
#endif

            // exchange a request token for an access token
            var accessToken = new DropBoxToken(result);

            // adjust the token
            if (accessToken.BaseTokenInformation == null)
            {
                accessToken.BaseTokenInformation                = new DropBoxBaseTokenInformation();
                accessToken.BaseTokenInformation.ConsumerKey    = appkey;
                accessToken.BaseTokenInformation.ConsumerSecret = appsecret;
            }


            // go ahead
            return(accessToken);
        }
示例#7
0
        public OAuthToken GetAccessToken(OAuthServiceContext svcContext, OAuthConsumerContext conContext, OAuthToken requestToken)
        {
            var url = OAuthUrlGenerator.GenerateAccessTokenUrl(svcContext.AccessTokenUrl, conContext, requestToken);

            return(GetToken(url));
        }
示例#8
0
        public OAuthToken GetRequestToken(OAuthServiceContext svcContext, OAuthConsumerContext conContext)
        {
            var url = OAuthUrlGenerator.GenerateRequestTokenUrl(svcContext.RequestTokenUrl, conContext);

            return(GetToken(url));
        }