/// <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); }
/// <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> public static ICloudStorageAccessToken LoginWithMobileAPI(String username, String password, String appkey, String appsecret) { // get the configuration var 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 var svc = new OAuthService(); var oAuthRequestToken = svc.GetRequestToken(serviceContext, consumerContext); if (oAuthRequestToken == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidConsumerKeySecret); } var DropBoxRequestToken = new DropBoxToken(oAuthRequestToken, new DropBoxBaseTokenInformation {ConsumerKey = appkey, ConsumerSecret = appsecret}); // generate the dropbox service var 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 var 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 { ConsumerKey = appkey, ConsumerSecret = appsecret }; } // go ahead return accessToken; }