private void DropboxAuthStart() { OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = ConfigurationManager.AppSettings["DropboxCallback"] + "?dropboxcallback=1"; SaveSession(); Response.Redirect(AppCache.dropboxProvider.OAuthOperations.BuildAuthenticateUrl(AppCache.requestToken.Value, parameters)); }
public void BuildAuthorizeUrl_CustomAuthorizeParameters() { OAuth1Parameters oauth10Parameters = new OAuth1Parameters(); oauth10Parameters.CallbackUrl = "http://www.someclient.com/oauth/callback"; Assert.AreEqual(AUTHORIZE_URL + "?oauth_token=request_token&oauth_callback=http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback&custom_parameter=custom_parameter_value", customOauth10.BuildAuthorizeUrl("request_token", oauth10Parameters)); }
private static void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Console.WriteLine("Done."); OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl( oauthToken.Value, parameters); Console.WriteLine("Redirect the user for authorization to {0}", authenticateUrl); Process.Start(authenticateUrl); Console.Write("Press [Enter] when authorization attempt has succeeded."); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done."); string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
public void BuildAuthorizeUrl_CustomAuthorizeParameters() { OAuth1Parameters oauth10Parameters = new OAuth1Parameters(); oauth10Parameters.CallbackUrl = "http://www.someclient.com/oauth/callback"; Assert.AreEqual(AUTHORIZE_URL + "?oauth_token=request_token&oauth_callback=http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback&custom_parameter=custom_parameter_value", customOauth10.BuildAuthorizeUrl("request_token", oauth10Parameters)); }
// GET: /Dropbox/SignIn public ActionResult SignIn() { OAuthToken requestToken = dropboxProvider.OAuthOperations.FetchRequestTokenAsync(null , null).Result; Session["RequestToken"] = requestToken; OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = "http://localhost/Dropbox/Callback"; //parameters.Add("locale", System.Globalization.CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website return Redirect(dropboxProvider.OAuthOperations.BuildAuthenticateUrl(requestToken.Value, parameters)); }
/// <summary> /// Construct the URL to redirect the user to for authentication. /// The authenticate URL differs from the authorizationUrl slightly in that it does not require the user to authorize the app multiple times. /// This provides a better user experience for "Sign in with Provider" scenarios. /// </summary> /// <param name="requestToken">The request token value, to be encoded in the authorize URL</param> /// <param name="parameters">Parameters to pass to the provider in the authenticate URL. May be null.</param> /// <returns>The absolute authenticate URL to redirect the user to for authentication</returns> public string BuildAuthenticateUrl(string requestToken, OAuth1Parameters parameters) { if (this.authenticateUrl != null) { return(this.BuildAuthUrl(this.authenticateUrl, requestToken, parameters)); } else { return(this.BuildAuthorizeUrl(requestToken, parameters)); } }
private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider) { OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; OAuth1Parameters parameters = new OAuth1Parameters(); string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Process.Start(authenticateUrl); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret }; File.WriteAllLines(OAuthTokenFileName, oauthData); }
private string BuildAuthUrl(string baseAuthUrl, string requestToken, OAuth1Parameters parameters) { StringBuilder authUrl = new StringBuilder(baseAuthUrl); authUrl.Append("?oauth_token=").Append(HttpUtils.UrlEncode(requestToken)); NameValueCollection authorizationParameters = parameters ?? new NameValueCollection(); this.AddCustomAuthorizationParameters(authorizationParameters); foreach (string additionalParameterName in authorizationParameters) { string additionalParameterNameEncoded = HttpUtils.UrlEncode(additionalParameterName); foreach (string additionalParameterValue in authorizationParameters.GetValues(additionalParameterName)) { authUrl.Append('&').Append(additionalParameterNameEncoded).Append('=').Append(HttpUtils.UrlEncode(additionalParameterValue)); } } return(authUrl.ToString()); }
private string BuildAuthUrl(string baseAuthUrl, string requestToken, OAuth1Parameters parameters) { StringBuilder authUrl = new StringBuilder(baseAuthUrl); authUrl.Append("?oauth_token=").Append(HttpUtils.UrlEncode(requestToken)); NameValueCollection authorizationParameters = parameters ?? new NameValueCollection(); this.AddCustomAuthorizationParameters(authorizationParameters); foreach (string additionalParameterName in authorizationParameters) { string additionalParameterNameEncoded = HttpUtils.UrlEncode(additionalParameterName); foreach (string additionalParameterValue in authorizationParameters.GetValues(additionalParameterName)) { authUrl.Append('&').Append(additionalParameterNameEncoded).Append('=').Append(HttpUtils.UrlEncode(additionalParameterValue)); } } return authUrl.ToString(); }
/// <summary> /// Construct the URL to redirect the user to for authorization. /// </summary> /// <param name="requestToken">The request token value, to be encoded in the authorize URL</param> /// <param name="parameters">Parameters to pass to the provider in the authorize URL. May be null.</param> /// <returns>The absolute authorize URL to redirect the user to for authorization</returns> public string BuildAuthorizeUrl(string requestToken, OAuth1Parameters parameters) { return this.BuildAuthUrl(this.authorizeUrl, requestToken, parameters); }
/// <summary> /// Construct the URL to redirect the user to for authentication. /// The authenticate URL differs from the authorizationUrl slightly in that it does not require the user to authorize the app multiple times. /// This provides a better user experience for "Sign in with Provider" scenarios. /// </summary> /// <param name="requestToken">The request token value, to be encoded in the authorize URL</param> /// <param name="parameters">Parameters to pass to the provider in the authenticate URL. May be null.</param> /// <returns>The absolute authenticate URL to redirect the user to for authentication</returns> public string BuildAuthenticateUrl(string requestToken, OAuth1Parameters parameters) { if (this.authenticateUrl != null) { return this.BuildAuthUrl(this.authenticateUrl, requestToken, parameters); } else { return this.BuildAuthorizeUrl(requestToken, parameters); } }
private void DropboxAuth() { try { OAuthToken requestToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; Response.Cookies["requestTokenValue"].Value = requestToken.Value; Response.Cookies["requestTokenSecret"].Value = requestToken.Secret; OAuth1Parameters parameters = new OAuth1Parameters(); parameters.CallbackUrl = Request.Url.ToString(); string authorizeUrl = dropboxServiceProvider.OAuthOperations.BuildAuthenticateUrl(requestToken.Value, parameters); Response.Redirect(authorizeUrl); } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { ErrorLabel.Text = ex.Message; return true; } return false; }); } }
static void Main(string[] args) { try { DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full); #if NET_4_0 /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null , null).Result; Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result; Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfileAsync().Result; Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* DeltaPage deltaPage = dropbox.DeltaAsync(null).Result; Entry createFolderEntry = dropbox.CreateFolderAsync("Spring Social").Result; Entry uploadFileEntry = dropbox.UploadFileAsync( new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), "/Spring Social/File.txt", true, null, CancellationToken.None).Result; FileRef fileRef = dropbox.CreateFileRefAsync("Spring Social/File.txt").Result; Entry copyRefEntry = dropbox.CopyFileRefAsync(fileRef.Value, "Spring Social/File_copy_ref.txt").Result; Entry copyEntry = dropbox.CopyAsync("Spring Social/File.txt", "Spring Social/File_copy.txt").Result; Entry deleteEntry = dropbox.DeleteAsync("Spring Social/File.txt").Result; Entry moveEntry = dropbox.MoveAsync("Spring Social/File_copy.txt", "Spring Social/File.txt").Result; dropbox.DownloadFileAsync("Spring Social/File.txt") .ContinueWith(task => { Console.WriteLine("File '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); // Save file to "C:\Spring Social.txt" using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) { fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); } }); Entry folderMetadata = dropbox.GetMetadataAsync("Spring Social").Result; IList<Entry> revisionsEntries = dropbox.GetRevisionsAsync("Spring Social/File.txt").Result; Entry restoreEntry = dropbox.RestoreAsync("Spring Social/File.txt", revisionsEntries[2].Revision).Result; IList<Entry> searchResults = dropbox.SearchAsync("Spring Social/", ".txt").Result; DropboxLink shareableLink = dropbox.GetShareableLinkAsync("Spring Social/File.txt").Result; DropboxLink mediaLink = dropbox.GetMediaLinkAsync("Spring Social/File.txt").Result; Entry uploadImageEntry = dropbox.UploadFileAsync( new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), "/Spring Social/Image.png", true, null, CancellationToken.None).Result; dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium) .ContinueWith(task => { Console.WriteLine("Thumbnail '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size); // Save file to "C:\Thumbnail_Medium.png" using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) { fileStream.Write(task.Result.Content, 0, task.Result.Content.Length); } }); */ } catch (AggregateException ae) { ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); return true; } return false; }); } #else /* OAuth 1.0 'dance' */ // Authorization without callback url Console.Write("Getting request token..."); OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null); Console.WriteLine("Done"); OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters); Console.WriteLine("Redirect user for authorization"); Process.Start(authenticateUrl); Console.Write("Press any key when authorization attempt has succeeded"); Console.ReadLine(); Console.Write("Getting access token..."); AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null); OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null); Console.WriteLine("Done"); /* API */ IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret); //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag; DropboxProfile profile = dropbox.GetUserProfile(); Console.WriteLine("Hi " + profile.DisplayName + "!"); // Use step by step debugging, or not /* DeltaPage deltaPage = dropbox.Delta(null); Entry createFolderEntry = dropbox.CreateFolder("Spring Social"); Entry uploadFileEntry = dropbox.UploadFile( new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"), "/Spring Social/File.txt", true, null); FileRef fileRef = dropbox.CreateFileRef("Spring Social/File.txt"); Entry copyRefEntry = dropbox.CopyFileRef(fileRef.Value, "Spring Social/File_copy_ref.txt"); Entry copyEntry = dropbox.Copy("Spring Social/File.txt", "Spring Social/File_copy.txt"); Entry deleteEntry = dropbox.Delete("Spring Social/File.txt"); Entry moveEntry = dropbox.Move("Spring Social/File_copy.txt", "Spring Social/File.txt"); var fileCanceler = dropbox.DownloadFileAsync("Spring Social/File.txt", r => { Console.WriteLine("File '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); // Save file to "C:\Spring Social.txt" using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create)) { fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); } }); Entry folderMetadata = dropbox.GetMetadata("Spring Social"); IList<Entry> revisionsEntries = dropbox.GetRevisions("Spring Social/File.txt"); Entry restoreEntry = dropbox.Restore("Spring Social/File.txt", revisionsEntries[2].Revision); IList<Entry> searchResults = dropbox.Search("Spring Social/", ".txt"); DropboxLink shareableLink = dropbox.GetShareableLink("Spring Social/File.txt"); DropboxLink mediaLink = dropbox.GetMediaLink("Spring Social/File.txt"); Entry uploadImageEntry = dropbox.UploadFile( new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"), "/Spring Social/Image.png", true, null); var thumbnailCanceler = dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium, r => { Console.WriteLine("Thumbnail '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size); // Save file to "C:\Thumbnail_Medium.png" using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create)) { fileStream.Write(r.Response.Content, 0, r.Response.Content.Length); } }); */ }
public void LinkApp(object view) { try { if (OnCloudAuthenticationStatusChanged != null) OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.GetRequestToken); // If the Initialize method has failed the service provider will be null! if(_dropboxServiceProvider == null) _dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.AppFolder); // Authorization without callback url _oauthToken = _dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result; if (OnCloudAuthenticationStatusChanged != null) OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.OpenWebBrowser); AuthenticationToken token = null; try { // Try to get a previously saved token token = LoadTokenFromDisk(); } catch { // Ignore exception; use the web browser to get a new token } if (token == null) { // Open web browser for authentication OAuth1Parameters parameters = new OAuth1Parameters(); //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website string authenticateUrl = _dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(_oauthToken.Value, parameters); Process.Start(authenticateUrl); } else { ContinueLinkApp(token); } } catch (AggregateException ae) { HasLinkedAccount = false; ae.Handle(ex => { if (ex is DropboxApiException) { Console.WriteLine(ex.Message); return true; } return false; }); } }
/// <summary> /// Construct the URL to redirect the user to for authorization. /// </summary> /// <param name="requestToken">The request token value, to be encoded in the authorize URL</param> /// <param name="parameters">Parameters to pass to the provider in the authorize URL. May be null.</param> /// <returns>The absolute authorize URL to redirect the user to for authorization</returns> public string BuildAuthorizeUrl(string requestToken, OAuth1Parameters parameters) { return(this.BuildAuthUrl(this.authorizeUrl, requestToken, parameters)); }