This project is read-only.

Dropbox authorization

Sep 29, 2011 at 4:30 PM

Hi,

I've trying to connect to a Dropbox account using the following:

	
public bool Login(string login, string password)
        {
            try
            {
                // instanciate a new credentials object, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials credentials = new AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials();
 
                // attach the application information 
                credentials.ConsumerKey = Appkey;
                credentials.ConsumerSecret = AppSecret;
 
                // add the account information
                credentials.UserName = login;
                credentials.Password = password;
 
                // instanciate a cloud storage configuration, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration configuration = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration();
 
                // open the connection to the storage
                m_accessToken = m_storage.Open(configuration, credentials);
 
                return true;
            }
            catch
            {
                return false;
            }
        }

My problem is that I get an unauthorizedAccess exception. This is due to the fact that the Dropbox account hasn't authorized my application.
How to get this authorization with SharpBox ?

Thanks in advance.
Frédéric.
Sep 29, 2011 at 7:26 PM
Hi,


It's the best way to be DropBox compliant if you work on desktop or ASP.NET applications.

I will add this in a tutorial and let you know

Cheers
Dirk


2011/9/29 fnaudeau <notifications@codeplex.com>

From: fnaudeau

Hi,

I've trying to connect to a Dropbox account using the following:

	
public bool Login(string login, string password)
        {
            try
            {
                // instanciate a new credentials object, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials credentials = new AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials();
 
                // attach the application information 
                credentials.ConsumerKey = Appkey;
                credentials.ConsumerSecret = AppSecret;
 
                // add the account information
                credentials.UserName = login;
                credentials.Password = password;
 
                // instanciate a cloud storage configuration, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration configuration = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration();
 
                // open the connection to the storage
                m_accessToken = m_storage.Open(configuration, credentials);
 
                return true;
            }
            catch
            {
                return false;
            }
        }

My problem is that I get an unauthorizedAccess exception. This is due to the fact that the Dropbox account hasn't authorized my application.
How to get this authorization with SharpBox ?

Thanks in advance.
Frédéric.

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Sep 29, 2011 at 10:30 PM
Hi,

I added a new tutorial for this on our project page: http://sharpbox.codeplex.com/wikipage?title=SharpBox%20Developer%20Tutorials

Cheers
Dirk


2011/9/29 Dirk Eisenberg <dirk.eisenberg@gmail.com>
Hi,


It's the best way to be DropBox compliant if you work on desktop or ASP.NET applications.

I will add this in a tutorial and let you know

Cheers
Dirk


2011/9/29 fnaudeau <notifications@codeplex.com>

From: fnaudeau

Hi,

I've trying to connect to a Dropbox account using the following:

	
public bool Login(string login, string password)
        {
            try
            {
                // instanciate a new credentials object, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials credentials = new AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxCredentials();
 
                // attach the application information 
                credentials.ConsumerKey = Appkey;
                credentials.ConsumerSecret = AppSecret;
 
                // add the account information
                credentials.UserName = login;
                credentials.Password = password;
 
                // instanciate a cloud storage configuration, e.g. for dropbox
                AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration configuration = AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration();
 
                // open the connection to the storage
                m_accessToken = m_storage.Open(configuration, credentials);
 
                return true;
            }
            catch
            {
                return false;
            }
        }

My problem is that I get an unauthorizedAccess exception. This is due to the fact that the Dropbox account hasn't authorized my application.
How to get this authorization with SharpBox ?

Thanks in advance.
Frédéric.

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



Oct 3, 2011 at 9:34 AM

Thanks Dirk for your tutorial.

I have one more question concerning the AuthorizationCallBack. 

Indeed, as my application is a desktop application, I don't have a "callback url" ( config.AuthorizationCallBack = new Uri(_AuthorizationCallbackUri); ), so how can I manage to get the feedback it has successfully logged in.

I'm also trying to get rid of the webbrowser control, and post the authentication form via HttpRequest, but this callback url is confusing my understanding.

Thanks for your help.

Frédéric.

Oct 3, 2011 at 11:18 AM
Hi,

to your first question, you can use any authorization URL as callback. If you do not have one just use SharpBox.codeplex.com. It is not important for the authorization process as self.

Get rid of the web browser control is against the rules of DropBox and the Ajax based user interface which you need to control remote is very complex. The easiest way is to implement a wizard for your customers for generate the token one times

Cheers
Dirk

Sent from my iPad

On 03.10.2011, at 10:34, fnaudeau <notifications@codeplex.com> wrote:

From: fnaudeau

Thanks Dirk for your tutorial.

I have one more question concerning the AuthorizationCallBack.

Indeed, as my application is a desktop application, I don't have a "callback url" ( config.AuthorizationCallBack = new Uri(_AuthorizationCallbackUri); ), so how can I manage to get the feedback it has successfully logged in.

I'm also trying to get rid of the webbrowser control, and post the authentication form via HttpRequest, but this callback url is confusing my understanding.

Thanks for your help.

Frédéric.

Oct 3, 2011 at 1:02 PM

Hi,

What do you mean by "The easiest way is to implement a wizard for your customers for generate the token one times" ?

My main concern is to embed the Dropbox connection in a "kiosk" application. So I have to simplify the life of the customer and avoid to display a webpage to him. 

The goal will be for the user to input his login and password, and that's all. 

Is this possible ?

Frédéric.

Oct 3, 2011 at 10:25 PM
Hi,

technical you can do this via Login API (SharpBox supports this as well). This API is an API for mobile applications only so you will not get an approval from DropBox for your implementation. Best thing is to open a support request at DropBox to get advice what is a way this guys will accept!

I personally think they will say you something like this:

1. User enter username and password
2. If you have no token stored for this user got through the validation process
3. Open the web browser control only when the customer needs to accept the application usage

that's it

Sorry for no better news
Dirk


2011/10/3 fnaudeau <notifications@codeplex.com>

From: fnaudeau

Hi,

What do you mean by "The easiest way is to implement a wizard for your customers for generate the token one times" ?

My main concern is to embed the Dropbox connection in a "kiosk" application. So I have to simplify the life of the customer and avoid to display a webpage to him.

The goal will be for the user to input his login and password, and that's all.

Is this possible ?

Frédéric.

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Oct 4, 2011 at 8:50 PM
Edited Oct 4, 2011 at 8:59 PM

Dirk -

I have everything working through the callback.  I get back a uid and oauth_token.  I assume I will use them as username and password repsectively.  Correct?

There's third step in your tutorial.  When is this supposted to be called and who need this token?

My code is failing in the second method attached - storge.Open(.....

Please let me know if I'm miss understanding anything.

Here's the code to get the authoriation from dropbox -


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim lastSlash As Integer = Request.Url.OriginalString.LastIndexOf("/")
        urlPath = Request.Url.OriginalString.Substring(0, lastSlash)

        cburi = urlPath + cburi

        ' get the config of dropbox
        Dim config As DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)
        ' set your own callback which will be called from DropBox after successful
        ' authorization
        config.AuthorizationCallBack = New Uri(cburi + "?oid=1234567")
        ' create a request token
        Dim requestToken As Object = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ConsumerSecret)

        If requestToken Is Nothing = False Then
            ' call the authorization url via WebBrowser Plugin
            Dim AuthorizationUrl As String = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken)

            bOpenDropBox.Attributes.Add("onclick", "javascript: window.open('" + AuthorizationUrl + "','','');")

        End If


    End Sub

This code is to test the connection to dropbox -

Public Sub SaveJob()
        Dim storage As CloudStorage = Nothing

        Try

            '' instanciate a new credentials object, e.g. for dropbox
            Dim credentials As DropBoxCredentials = New DropBoxCredentials()

            ' attach the application information
            credentials.ConsumerKey = ConsumerKey
            credentials.ConsumerSecret = ConsumerSecret

            ' add the account information
            credentials.UserName = tbuid.Text  

            credentials.Password = tbtoken.Text   '""

            ' instanciate a cloud storage configuration, e.g. for dropbox
            Dim dconfig As DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)


            ' instanciate the cloudstorage manager
            storage = New CloudStorage()

            ' open the connection to the storage
            storage.Open(dconfig, credentials)

            Dim sbFolder As ICloudDirectoryEntry = Nothing
            Try
                sbFolder = storage.GetFolder("/MyApp")
            Catch ex As Exception

            End Try


            If sbFolder Is Nothing Then
                ' create the schoolbrains folder in the root directory
                sbFolder = storage.CreateFolder("MyApp", Nothing)
                If sbFolder Is Nothing Then
                    Console.WriteLine("Couldn't create MyApp")
                End If

            End If

            If sbFolder Is Nothing = False Then

                ' create the folder in the root directory
                Dim newFolder As ICloudDirectoryEntry = storage.CreateFolder(aJobName, sbFolder)
                If newFolder Is Nothing Then

                    Console.WriteLine("Couldn't create MyFirstFolder")
                End If


                If newFolder Is Nothing = False Then

                    Dim imagePath As String = HttpContext.Current.Server.MapPath("./files/" + aJobName)
                    Dim s As String
                    For Each s In Directory.EnumerateFiles(imagePath)
                        storage.UploadFile(s, newFolder)
                    Next

                End If

            End If

 


        Catch ex As Exception
            Debug.WriteLine(ex.ToString)
        Finally
            ' close the cloud storage connection
            If storage Is Nothing = False Then
                If storage.IsOpened Then
                    storage.Close()
                End If
            End If

        End Try

    End Sub

 

Oct 4, 2011 at 10:56 PM
Hi,

the third step should be called after you requested the authorization URI to exchange your request token in a access token. The access token is to one you should use in the Open-Method instead of username and password. You can't use a request token, you have to exchange the request token after calling the authorization url.

Does it help?
Dirk


2011/10/4 hedgefence <notifications@codeplex.com>

From: hedgefence

Dirk -

I have everything working through the callback. I get back a uid and oauth_token. I assume I will use them as username and password repsectively. Correct?

There's third step in your tutorial. When is this supposted to be called and who need this token?

My code is failing in the second method attached - storge.Open(.....

Please let me know if I'm miss understanding anything.

Here's the code to get the authoriation from dropbox -


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim lastSlash As Integer = Request.Url.OriginalString.LastIndexOf("/")
urlPath = Request.Url.OriginalString.Substring(0, lastSlash)

cburi = urlPath + cburi

' get the config of dropbox
Dim config As DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)
' set your own callback which will be called from DropBox after successful
' authorization
config.AuthorizationCallBack = New Uri(cburi + "?oid=1234567")
' create a request token
Dim requestToken As Object = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ConsumerSecret)

If requestToken Is Nothing = False Then
' call the authorization url via WebBrowser Plugin
Dim AuthorizationUrl As String = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken)

bOpenDropBox.Attributes.Add("onclick", "javascript: window.open('" + AuthorizationUrl + "','','');")

End If


End Sub

This code is to test the connection to dropbox -

Public Sub SaveJob()
Dim storage As CloudStorage = Nothing

Try

'' instanciate a new credentials object, e.g. for dropbox
Dim credentials As DropBoxCredentials = New DropBoxCredentials()

' attach the application information
credentials.ConsumerKey = ConsumerKey
credentials.ConsumerSecret = ConsumerSecret

' add the account information
credentials.UserName = tbuid.Text '"rob.pemberton@aptium.com"
credentials.Password = tbtoken.Text '""

' instanciate a cloud storage configuration, e.g. for dropbox
Dim dconfig As DropBoxConfiguration = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)


' instanciate the cloudstorage manager
storage = New CloudStorage()

' open the connection to the storage
storage.Open(dconfig, credentials)

Dim sbFolder As ICloudDirectoryEntry = Nothing
Try
sbFolder = storage.GetFolder("/MyApp")
Catch ex As Exception

End Try


If sbFolder Is Nothing Then
' create the schoolbrains folder in the root directory
sbFolder = storage.CreateFolder("MyApp", Nothing)
If sbFolder Is Nothing Then
Console.WriteLine("Couldn't create MyApp")
End If

End If

If sbFolder Is Nothing = False Then

' create the folder in the root directory
Dim newFolder As ICloudDirectoryEntry = storage.CreateFolder(aJobName, sbFolder)
If newFolder Is Nothing Then

Console.WriteLine("Couldn't create MyFirstFolder")
End If


If newFolder Is Nothing = False Then

Dim imagePath As String = HttpContext.Current.Server.MapPath("./files/" + aJobName)
Dim s As String
For Each s In Directory.EnumerateFiles(imagePath)
storage.UploadFile(s, newFolder)
Next

End If

End If


Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
' close the cloud storage connection
If storage Is Nothing = False Then
If storage.IsOpened Then
storage.Close()
End If
End If

End Try

End Sub

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Oct 5, 2011 at 12:31 PM

Thanks Dirk -  That helps.  It would be helpfull if your tutorial had a code snipet that used the correct token and storage.open method.  Save others some time.

Oct 5, 2011 at 10:46 PM
Hi,

thanks for your feedback, it's a real good idea and I will update the tutorial on the weekend.

Thanks in advance again for the feedback on our work
Cheers
Dirk


2011/10/5 hedgefence <notifications@codeplex.com>

From: hedgefence

Thanks Dirk - That helps. It would be helpfull if your tutorial had a code snipet that used the correct token and storage.open method. Save others some time.

Read the full discussion online.

To add a post to this discussion, reply to this email (sharpbox@discussions.codeplex.com)

To start a new discussion for this project, email sharpbox@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com