I have successfully setup the oauth authentication to access my dropbox using sharpbox. Sharpbox is an open source "front end" that handles the nuts and bolts of the process. Using it i can return file info in a particular folder in my account.
I bind the filename and a generated URI to a gridview in a VS 2010 web app. I have a hyperlink with the text set to name and the DataNavigateUrlFields to the unique URL. It works great IF there is no "+" character in the oauth_signature part of the url string. If the plus is there, it returns "{"error": "Invalid signature. Expected signature base string:"
Thanks for your consideration.
Thank you for your help, here is my code
Public Sub MakeURL()
dbOpen()
Dim myfolder As ICloudDirectoryEntry = dropBoxStorage.GetFolder("/DIR/SUBDIR/")
Filename = Filename & "_POID_" & poid & ".pdf"
pdfurl = dropBoxStorage.GetFileSystemObjectUrl(Filename, myfolder).ToString
dbClose()
pdfurl = pdfurl.Replace("+", "%2B")
Response.Redirect(pdfurl)
End Sub
OAuth 1 Signature uses Percent Encoding (See RFC 5849). The specification clearly states that a space should not be encoded to a +, instead it should be encoded with %20. Replace your + with %20.
Related
I use Rest Assured framework (Java).
I need to send integer array as http-param in get request: http://example.com:8080/myservice?data_ids=11,22,33
Integer[] ids = new Integer[] {11, 22, 33};
...
RequestSpecificationImpl request = (RequestSpecificationImpl)RestAssured.given();
request.baseUri("http://example.com");
request.port(8080);
request.basePath("/myservice");
...
String ids_as_string = Arrays.toString(ids).replaceAll("\\s|[\\[]|[]]", "");
request.params("data_ids", ids_as_string);
System.out.println("Params: " + request.getRequestParams().toString());
System.out.println("URI" + request.getURI());
What I see in the console:
Params: {data_ids=11,22,33}
URI: http://example.com:8080/myservice?data_ids=11%2C22%2C33
Why do my commas transform into '%2C'?
What needs to be done to ensure that commas are passed as they should?
Disable URL encoding, simple as that
given().urlEncodingEnabled(false);
Official documentation
Verified locally,
I want to share files from MS OneDrive to a user via MS graph API. And user can view my shared file directly through the link. I have read the Document of Creating a sharing Link for a DriveItem and use this API to create a sharing link for my sharing files.
I wonder how to implement with MS graph API? Any suggestion and tips are welcome. Thanks
According to your description, I assume you want to get the share file by using MS Graph API.
Base on my test, We can create a shareLink for this this file.
Then we can use the following steps to get the file information by converting the shareLink.
Encoding the shareLink by using the following logic:
1)First, use base64 encode the URL.
2)Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
3)Append u! to be beginning of the string.
If you want access the shared files, you can use the following API:
GET /shares/{shareIdOrUrl}/driveItem
The shareIdOrUrl parameter is the result in step1.
This API will return all the information about the shared file.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
For more detail, we can refer to this document.
I have a website using angular.js and my backend is using asp.net web api. When a new user register a e-mail is send with an activation link and a token inside it like this :
localhost:51426/#/activation?userid=test&code=FCuuf27NzVvmwp2Ksd7IDt83C2XZmZ2paCrZPBLgr9qR8xCaXELvqKCsWlg4uiokb07XK5sQ+2BazHN1+2B74q14grkQY2OHDAVeWlin5GE8ugkyw+2BJFFzd3Q2YiVuMxkmkO6OFdhIyfzUQMV8NPipME+2FST1pa0OuQs90kRUNR5kTkPlGQYKflDOMQvDGV84fZIw
When the user click the link I have an angular controller that basically just take the parameter and call the good method inside the web.api like this :
return $http.post(baseUrl + 'api/v1/account/confirmAccount?userId=' + userId + '&code=' + code);
The problem it seems all the + are replace by space in the server side so when I try to validate the token in my web api it doesn't work.
Not sure to understand why the + it's replace by space and how to avoid this.
Thanks
The problem is that in query strings + characters are replaced by spaces:
URL Encoding:
The HTML specifies the following transformation:
SPACE is encoded as '+' or "%20" [9]
What you could do is replace the space characters with + on the server:
string newCode=code.Replace(' ','+')
One option might be to build the string first and eliminate the + altogether.
I use WCF and have a method like this:
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "LoadProducts/{key}/{price}")]
XmlDocument LoadProducts(string key, string price= null);
price is string, inside LoadProducts I will try to parse it from string to double and do my other operations.
But in url, I can not get request any parameter for price like '24.25', '0.253' etc. It does not allow any value with dot.
localhost:13448/RestService.svc/LoadProducts/null/41.145
I get error "Please review the following URL and make sure that it is spelled correctly. "
How can I solve this?
Dots already have a meaning in a URL, they separate the target hostname, IP address or in the path they separate the resources from its extension. You will need to URL encode your request URL.
In .NET there is a method called UrlEncode to help you encode URLs. It is:
string url = "http://localhost/MyService/MyKey/24.25";
string encodedUrl = HttpUtility.UrlEncode(url);
Check out the MSN documentation for UrlEncode for more details.
I solved my issue. I switched server from Visual Studio Development Server to Local IIS Web Server, url took dot symbol inside parameter.
I'm working on twitter client for win8, using RestSharp ( http://restsharp.org/ ) and I have such problem:
When I'm posting new tweet with RestClient
var timeLine = new RestRequest("/1/statuses/update.json", Method.POST);
var txt = "Hello world";
timeLine.AddParameter("status", txt);
everything works excelent, but if I add more complex status like:
var txt = "Hello, World! What a nice day! #1May";
timeLine.AddParameter("status", txt);
I recieve 401 error. In debugger I saw, that status parameter in Signature Base String is incorrect. I have:
status%3DHello%2C%2520World%21%2520What%2520a%2520nice%2520day%21%2520%231May
and right string (from dev.twitter.com):
status%3DHello%252C%2520World%2521%2520What%2520a%2520nice%2520day%2521%2520%25231May
You can see, that punctuation marks ,!# and other encodes incorrect. How can I fix it?
Signature base generation and Encoding are in /Authenticators/OAuth/OAuthTools.cs
I have the same problem when I display twitter feed in website. Hence, I used this code to convert the text.
Regex.Replace(str, "#(.*?):", #"#http://twitter.com/#!/$1>$1:");