|
|
Hi,
I'm wondering if there is a workflow for webapps to approve a token that doesn't require the website to request the users password. Currently my understanding is the current SharpBox workflow involves the application handling the users password which shouldn't
be required for a webapp. I should in theory be able to pass the user back to an authorisation page for the user to "approve" dropbox rather then my app handling passwords. Hopefully there is a workflow around this but my current thoughts are around trying
the following workflow: (sorry it's ironpython, I find it easier)
token = OAuthService.GetRequestToken(svcContext, conContext)
dropboxCredentials = DropBoxCredentialsToken('xxx', 'xxx', token.TokenKey, token.TokenSecret)
tokenstream = storage.SerializeSecurityToken(dropboxCredentials.AccessToken)
tokenfile = FileStream(username+'.dtok', FileMode.Create)
tokenstream.CopyTo(tokenfile)
authorizationurl = OAuthService.GetAuthorizationUrl(svcContext, token)
print authorizationurl
All of this seems to work except for the SerializeSecurityToken fails with a {"Object reference not set to an instance of an object."} in {AppLimit.CloudComputing.SharpBox.Net40, Version=1.0.3.261, Culture=neutral, PublicKeyToken=null}. Have I misunderstood
the workflow? I couldn't find any SharpBox documentation around this. Thanks!
|
|
|
|
|
I think my problem is I need to create an instance of DropBoxToken(OAuthToken token) but DropBoxToken is an internal class :(. So the case I mention above "sending to user to dropbox to approve token" is not supported? If this is the case I am more then
happy to add this workflow if someone wants to discuss the most appropriate methods for this.
|
|
|
Coordinator
May 2 2011 at 7:16 AM
|
Hi,
you are right, a web app willl end up with a token key and secret and this has to be transformed into the internal class. The best way would be to use our serialize methods. Please send me the piece of code which throws the exception so that I can find
the reason.
It would also be a cool feature to implement a static method from the dropbox provider to generate the token given by key and secret. So let me think about it when I dig into your code sample ;-)
Thanks
Dirk
Sent from my iPad
From: BabyGGyt
I think my problem is I need to create an instance of DropBoxToken(OAuthToken token) but DropBoxToken is an internal class :(. So the case I mention above "sending to user to dropbox to approve token" is not supported? If this is the case I am more then
happy to add this workflow if someone wants to discuss the most appropriate methods for this.
|
|
|
|
|
using System;
using System.IO;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.OAuth;
using AppLimit.CloudComputing.OAuth.Context;
using AppLimit.CloudComputing.OAuth.Token;
class Class1
{
static void Main()
{
OAuthServiceContext svcContext = new OAuthServiceContext("https://api.dropbox.com/0/oauth/request_token", "https://www.dropbox.com/0/oauth/authorize", "http://localhost", "https://api.dropbox.com/0/oauth/access_token");
OAuthConsumerContext conContext = new OAuthConsumerContext("xxx", "xxx");
CloudStorage storage = new CloudStorage();
OAuthToken token = OAuthService.GetRequestToken(svcContext, conContext);
AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken dropboxCredentials = new AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken("xxx", "xxx", token.TokenKey, token.TokenSecret);
Stream tokenstream = storage.SerializeSecurityToken(dropboxCredentials.AccessToken);
Stream tokenfile = new FileStream("username.tok", FileMode.Create);
tokenstream.CopyTo(tokenfile);
tokenfile.Close();
string authorizationurl = OAuthService.GetAuthorizationUrl(svcContext, token);
Console.WriteLine("I direct the user to " + authorizationurl + " correct?");
}
}
|
|
|
Coordinator
May 2 2011 at 11:23 PM
|
Hi,
a couple minutes ago I builded up a couple of tool function which should support your use case as well. Check out this sample in our documentation section:
http://sharpbox.codeplex.com/wikipage?title=Authorization%20via%20web%20based%20url&referringTitle=Documentation or from our trunk code!
I hope this helps, if so let me know. I will add it to the 1.1 release as well.
Cheers
Dirk
2011/5/2 BabyGGyt <notifications@codeplex.com>
From: BabyGGyt
using System;
using System.IO;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.OAuth;
using AppLimit.CloudComputing.OAuth.Context;
using AppLimit.CloudComputing.OAuth.Token;
class Class1
{
static void Main()
{
OAuthServiceContext svcContext = new OAuthServiceContext("https://api.dropbox.com/0/oauth/request_token", "https://www.dropbox.com/0/oauth/authorize", "http://localhost", "https://api.dropbox.com/0/oauth/access_token");
OAuthConsumerContext conContext = new OAuthConsumerContext("xxx", "xxx");
CloudStorage storage = new CloudStorage();
OAuthToken token = OAuthService.GetRequestToken(svcContext, conContext);
AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken dropboxCredentials = new AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken("xxx", "xxx", token.TokenKey, token.TokenSecret);
Stream tokenstream = storage.SerializeSecurityToken(dropboxCredentials.AccessToken);
Stream tokenfile = new FileStream("username.tok", FileMode.Create);
tokenstream.CopyTo(tokenfile);
tokenfile.Close();
string authorizationurl = OAuthService.GetAuthorizationUrl(svcContext, token);
Console.WriteLine("I direct the user to " + authorizationurl + " correct?");
}
}
|
|
|
|
|
Perfect! I'll try it out when I get a chance :). Thank you very much!
On Tue, May 3, 2011 at 9:23 AM, [email removed] wrote:
> From: dei79
>
> Hi,
>
> a couple minutes ago I builded up a couple of tool function which should
> support your use case as well. Check out this sample in our documentation
> section:
> http://sharpbox.codeplex.com/wikipage?title=Authorization%20via%20web%20based%20url&referringTitle=Documentation
> or from our trunk code!
>
> I hope this helps, if so let me know. I will add it to the 1.1 release as
> well.
>
> Cheers
> Dirk
>
> 2011/5/2 BabyGGyt <[email removed]>
>
> From: BabyGGyt
>
> using System;
> using System.IO;
> using AppLimit.CloudComputing.SharpBox;
> using AppLimit.CloudComputing.OAuth;
> using AppLimit.CloudComputing.OAuth.Context;
> using AppLimit.CloudComputing.OAuth.Token;
>
> class Class1
> {
> static void Main()
> {
> OAuthServiceContext svcContext = new
> OAuthServiceContext("https://api.dropbox.com/0/oauth/request_token",
> "https://www.dropbox.com/0/oauth/authorize", "http://localhost",
> "https://api.dropbox.com/0/oauth/access_token");
> OAuthConsumerContext conContext = new OAuthConsumerContext("xxx",
> "xxx");
> CloudStorage storage = new CloudStorage();
> OAuthToken token = OAuthService.GetRequestToken(svcContext,
> conContext);
> AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken
> dropboxCredentials = new
> AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentialsToken("xxx",
> "xxx", token.TokenKey, token.TokenSecret);
> Stream tokenstream =
> storage.SerializeSecurityToken(dropboxCredentials.AccessToken);
> Stream tokenfile = new FileStream("username.tok", FileMode.Create);
> tokenstream.CopyTo(tokenfile);
> tokenfile.Close();
> string authorizationurl =
> OAuthService.GetAuthorizationUrl(svcContext, token);
> Console.WriteLine("I direct the user to " + authorizationurl + "
> correct?");
> }
> }
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> 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
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe 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
|
|
|
|
|
Hello,
I've been reading the source code and specially the code related with http://sharpbox.codeplex.com/wikipage?title=Authorization%20via%20web%20based%20url&referringTitle=Documentation.
I think I'm missing something obvious. If someone could bring some light into this, it will be very much appreciated.
Once you have the Web Application authorized on the user's "My Apps" tab (https://www.dropbox.com/account#applications), let's say, a week later, how do I (the web app) reuse the authorization already
granted by the user?
// 5. Opent the storage with the generated access token
CloudStorage storageNew = new CloudStorage();
storageNew.Open(config, accessToken);
How do I know (and build) the "accessToken"?
Many thanks,
H.-
|
|
|
Coordinator
Aug 12 2011 at 11:24 AM
|
Hi,
sharpbox supports methods to Store and Load tokens into a .NET stream. The prefered way is that you store the received token during the authorization process on the server with CloudStorage.SerializeSecurityToken and if you need the token to get access
just load it with CloudStorage.DeserializeSecurityToken. The result can be used in the CloudStorage.Open method to get access to the cloud storage.
I hope this helps?
Cheers
Dirk
|
|
|
|
|
Hello Dirk,
Many thanks for your reply.
Yes, it does help, and now the code at the beginning of this thread makes more sense to me (where it does " tokenfile = FileStream(username+'.dtok', FileMode.Create) / tokenstream.CopyTo(tokenfile) "
My problem now is that SerializeSecurityToken throws a Null reference exception. I still couldn't figure out what to change to make this work.
After "// 3. Redirect the user to the website of dropbox", I'm doing:
// 4. Exchange the request token into access token
ICloudStorageAccessToken accessTokenFromOAuth = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ComsumerSecret, requestToken);
Note that accessTokenFromOAuth is not null and looks fine (on the debugger).
Then I do:
// Creates the dropBoxStorage
CloudStorage dropBoxStorage = new CloudStorage();
// Store the token in a stream
System.IO.Stream tokenStreamSaved = dropBoxStorage.SerializeSecurityToken(accessTokenFromOAuth);
At this point, "SerializeSecurityToken()" throws the null reference exception.
Unhandled Exception: System.NullReferenceException: Object reference not set toan instance of an object. at AppLimit.CloudComputing.SharpBox.CloudStorage.StoreToken(Dictionary`2 tokendata, ICloudStorageAccessToken token) at AppLimit.CloudComputing.SharpBox.CloudStorage.SerializeSecurityToken(ICloudStorageAccessToken token, Dictionary`2 additionalMetaData) at AppLimit.CloudComputing.SharpBox.CloudStorage.SerializeSecurityToken(IClou
the problem is here ("_configuration" is null)
internal void StoreToken(Dictionary<String, String> tokendata, ICloudStorageAccessToken token)
{
// add the configuration information into the
tokendata.Add(TokenProviderConfigurationType, _configuration.GetType().FullName);
tokendata.Add(TokenCredentialType, token.GetType().FullName);
// store all the other information to tokendata
_provider.StoreToken(tokendata, token);
}
Many thanks,
Horacio.-
|
|
|
Coordinator
Aug 15 2011 at 3:59 PM
|
Hi,
currently just open the connection before calling serialize :-)
I will add a bugfix to prevent this behaviour
Thanks
Dirk
2011/8/14 horacioj <notifications@codeplex.com>
From: horacioj
Hello Dirk,
Many thanks for your reply.
Yes, it does help, and now the code at the beginning of this thread makes more sense to me (where it does " tokenfile = FileStream(username+'.dtok', FileMode.Create) / tokenstream.CopyTo(tokenfile) "
My problem now is that SerializeSecurityToken throws a Null reference exception. I still couldn't figure out what to change to make this work.
After "// 3. Redirect the user to the website of dropbox", I'm doing:
// 4. Exchange the request token into access token
ICloudStorageAccessToken accessTokenFromOAuth = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ComsumerSecret, requestToken);
Note that accessTokenFromOAuth is not null and looks fine (on the debugger).
Then I do:
// Creates the dropBoxStorage
CloudStorage dropBoxStorage = new CloudStorage();
// Store the token in a stream
System.IO.Stream tokenStreamSaved = dropBoxStorage.SerializeSecurityToken(accessTokenFromOAuth);
At this point, "SerializeSecurityToken()" throws the null reference exception.
Unhandled Exception: System.NullReferenceException: Object reference not set toan instance of an object. at AppLimit.CloudComputing.SharpBox.CloudStorage.StoreToken(Dictionary`2 tokendata, ICloudStorageAccessToken token) at AppLimit.CloudComputing.SharpBox.CloudStorage.SerializeSecurityToken(ICloudStorageAccessToken token, Dictionary`2 additionalMetaData) at AppLimit.CloudComputing.SharpBox.CloudStorage.SerializeSecurityToken(IClou
the problem is here ("_configuration" is null)
internal void StoreToken(Dictionary<String, String> tokendata, ICloudStorageAccessToken token)
{
// add the configuration information into the
tokendata.Add(TokenProviderConfigurationType, _configuration.GetType().FullName);
tokendata.Add(TokenCredentialType, token.GetType().FullName);
// store all the other information to tokendata
_provider.StoreToken(tokendata, token);
}
Many thanks,
Horacio.-
|
|
|
|
|
Hi Dirk,
>open the connection before calling serialize
Many thanks! Now it works like a charm!
Best,
Horacio.-
|
|
|
|
|
Hello,
I'm now implementing 'the real life' case.
This is a two stages process.
- 1. Get the authorize url (and wait for the user to browse to dropbox.com and authorize the app)
- 2. Exchange the request token into access token, and save it (the access token) to be utilized in all future calls to dropbox.
The problem is that both steps needs to use the same requestToken. In other words, step "2" needs exactly the requestToken generated on step "1".
Object requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);
If you do this again, you get a different token.
Between 1 and 2 there is a postback.
My problem is, how can I save/remember the "requestToken" contents?
It's not serializable, and I cannot create a new one from its original contents (the TokenSecret and TokenKey values), because all related classes are internal (not public).
Thanks,
Horacio.-
|
|
|
Coordinator
Aug 22 2011 at 4:19 AM
|
I personally think we should make it serializable to handle this usecase! You can do this earliest in after this week (I'm on the road)!
2011/8/22 horacioj <notifications@codeplex.com>
From: horacioj
Hello,
I'm now implementing 'the real life' case.
This is a two stages process.
- 1. Get the authorize url (and wait for the user to browse to
dropbox.com and authorize the app)
- 2. Exchange the request token into access token, and save it (the access token) to be utilized in all future calls to dropbox.
The problem is that both steps needs to use the same requestToken. In other words, step "2" needs exactly the requestToken generated on step "1".
Object requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);
If you do this again, you get a different token.
Between 1 and 2 there is a postback.
My problem is, how can I save/remember the "requestToken" contents?
It's not serializable, and I cannot create a new one from its original contents (the TokenSecret and TokenKey values), because all related classes are internal (not public).
Thanks,
Horacio.-
|
|
|
|
|
dei79 wrote:
I personally think we should make it serializable to handle this usecase! You can do this earliest in after this week (I'm on the road)!
Yes, make it serializable will solve the problem.
Thanks!
|
|
|
Coordinator
Aug 27 2011 at 11:41 AM
|
Hi,
Thanks
Dirk
2011/8/23 horacioj <notifications@codeplex.com>
From: horacioj
dei79 wrote:
I personally think we should make it serializable to handle this usecase! You can do this earliest in after this week (I'm on the road)!
Yes, make it serializable will solve the problem.
Thanks!
|
|
|
|
|
Hi Dirk,
Thanks for implementing this.
The problem is that I still have to do a CloudStorage.Open() before trying any Serialize/Deserialize operation, right? (because otherwise I get a null reference exception)
At this stage, no "DropBoxCredentials" or "ICloudStorageAccessToken" already exists. How can an do the Serialize/Deserialize? Should I create a fake DropBoxCredentials()? I don't have the values yet (and I will never have the user's username and password).
Many thanks,
Horacio.-
|
|
|
Coordinator
Aug 27 2011 at 9:57 PM
|
Hi,
for deserialize not any more. This is fixed with this check in as well! For serialize you need an open connection, sorry.
Dirk
Sent from my iPad
From: horacioj
Hi Dirk,
Thanks for implementing this.
The problem is that I still have to do a CloudStorage.Open() before trying any Serialize/Deserialize operation, right? (because otherwise I get a null reference exception)
At this stage, no "DropBoxCredentials" or "ICloudStorageAccessToken" already exists. How can an do the Serialize/Deserialize? Should I create a fake DropBoxCredentials()? I don't have the values yet (and I will never have the user's username and password).
Many thanks,
Horacio.-
|
|
|
|
|
>For serialize you need an open connection
OK. How can I open the connection? (When generating the DropBoxRequestToken, I still do not have any 'valid' connection information)
in the [Test()] public·void·DropBoxSerializeRequestToken(), you are using "cloudStorage.DeserializeSecurityToken"
You have "cloudStorage" already open (using some credentials information), but in a real life, do you not have yet this createntials, beacause you are starting the proceess of getting them (you do not have it yet)
Am I missing something?
Thanks!
|
|
|
Coordinator
Aug 27 2011 at 10:37 PM
|
Hi,
yes you are right. Let me check what I can do ;-(
Dirk
Sent from my iPad
From: horacioj
>For serialize you need an open connection
OK. How can I open the connection? (When generating the DropBoxRequestToken, I still do not have any 'valid' connection information)
in the [Test()] public·void·DropBoxSerializeRequestToken(), you are using "cloudStorage.DeserializeSecurityToken"
You have "cloudStorage" already open (using some credentials information), but in a real life, do you not have yet this createntials, beacause you are starting the proceess of getting them (you do not have it yet)
Am I missing something?
Thanks!
|
|
|
Coordinator
Aug 28 2011 at 7:08 AM
|
Hi,
Thanks for your information
Dirk
2011/8/28 Dirk Eisenberg <dirk.eisenberg@gmail.com>
Hi,
yes you are right. Let me check what I can do ;-(
From: horacioj
>For serialize you need an open connection
OK. How can I open the connection? (When generating the DropBoxRequestToken, I still do not have any 'valid' connection information)
in the [Test()] public·void·DropBoxSerializeRequestToken(), you are using "cloudStorage.DeserializeSecurityToken"
You have "cloudStorage" already open (using some credentials information), but in a real life, do you not have yet this createntials, beacause you are starting the proceess of getting them (you do not have it yet)
Am I missing something?
Thanks!
|
|
|
|
|
Hi Dirk,
Many thanks for the quick turnaround.
Now the problem is that this fails:
String url = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
becasue on OAuthUrlGenerator.cs at static public String GenerateAuthorizationUrl(), requestToken.TokenKey is null (line 29)
inside the "requestToken" [{AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxRequestToken}] there is just a non-public member "RealToken" [{AppLimit.CloudComputing.SharpBox.Common.Net.oAuth.Token.OAuthToken}] which has a 'TokenKey' and 'TokenSecret'
the problem could be that it's a non-public member?
btw, serialization looks like:
<ArrayOfKeyValueOfstringstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><KeyValueOfstringstring><Key>TokenProvConfigType</Key><Value>AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenCredType</Key><Value>AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxRequestToken</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenDropBoxAppKey</Key><Value>a1a1a1a1a1a1a1a</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenDropBoxAppSecret</Key><Value>b2b2b2b2b2b2b2b</Value></KeyValueOfstringstring></ArrayOfKeyValueOfstringstring>
Is this ok? (there is no 'TokenKey' there)
Best regards,
Horacio.-
|
|
|
Coordinator
Aug 28 2011 at 2:45 PM
|
Hi,
Sorry was a missing method which used the olde typeless cast :-(
Thanks
Dirk
2011/8/28 horacioj <notifications@codeplex.com>
From: horacioj
Hi Dirk,
Many thanks for the quick turnaround.
Now the problem is that this fails:
String url = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
becasue on OAuthUrlGenerator.cs at static public String GenerateAuthorizationUrl(), requestToken.TokenKey is null (line 29)
inside the "requestToken" [{AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxRequestToken}] there is just a non-public member "RealToken" [{AppLimit.CloudComputing.SharpBox.Common.Net.oAuth.Token.OAuthToken}] which has a 'TokenKey' and 'TokenSecret'
the problem could be that it's a non-public member?
btw, serialization looks like:
<ArrayOfKeyValueOfstringstring xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><KeyValueOfstringstring><Key>TokenProvConfigType</Key><Value>AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxConfiguration</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenCredType</Key><Value>AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox.DropBoxRequestToken</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenDropBoxAppKey</Key><Value>a1a1a1a1a1a1a1a</Value></KeyValueOfstringstring><KeyValueOfstringstring><Key>TokenDropBoxAppSecret</Key><Value>b2b2b2b2b2b2b2b</Value></KeyValueOfstringstring></ArrayOfKeyValueOfstringstring>
Is this ok? (there is no 'TokenKey' there)
Best regards,
Horacio.-
|
|
|
|
|
It works, thanks!
Now I'm trying to figure out if the overall slowness is related with the DropBox API itself, or the SharpBox library (e.g. downloading a tiny file takes more time than what it could be expected).
Best regards,
Horacio.-
|
|
|
Coordinator
Aug 29 2011 at 8:57 PM
|
Hi,
I'm happy to hear from you. For me (I'm working just with bigger files) it looks like the offset for REST/HTTPS.
Thanks
Dirk
PS: If you find something, let me know. I will add every performance improvement to our code :-)
2011/8/29 horacioj <notifications@codeplex.com>
From: horacioj
It works, thanks!
Now I'm trying to figure out if the overall slowness is related with the DropBox API itself, or the SharpBox library (e.g. downloading a tiny file takes more time than what it could be expected).
Best regards,
Horacio.-
|
|