bash-onedrive-upload
bash-onedrive-upload copied to clipboard
New application type not supported
Hi,
To test this script out I created myself a new OneDrive account.
When creating an application (at https://account.live.com/developers/applications) I don't see how to 'switch the API Setting "Mobile or desktop client app" to "yes"'. I can however add a platform and I've added a 'Mobile application' (the other option is 'Web') and this automatically shows a Redirect URI which is greyed out and unchangeable: urn:ietf:wg:oauth:2.0:oob
When running onedrive-authorize and pasting the shown URL into a browser I get the response:
https://login.live.com/oauth20_desktop.srf?error=invalid_request&error_description=The%20provided%20value%20for%20the%20input%20parameter%20%27redirect_uri%27%20is%20not%20valid.%20The%20client%20application%20must%20be%20marked%20as%20%27mobile%27%2c%20or%20the%20value%20must%20be%20an%20absolute%20URL%20which%20matches%20the%20registered%20redirect%20URI.&lc=2057
Since this URL itself seems to be an error message I changed the URL to remove the portion from '&redirect_uri=' onwards and that errors with: https://login.live.com/err.srf?lc=2057#error=invalid_request&error_description=The+provided+request+must+include+a+%27redirect_uri%27+input+parameter.
I then changed the URL so the redirect URL was the one shown (by default) against my application and there is no response (just see a blank page with the original URL)
Any ideas as to how to resolve. I'm also interested in uploading files from Linux to SharePoint Online (part of Office365) so any idea whether the same mechanism could be used for that.
Thanks, Nik
The provided value for the input parameter 'redirect_uri' is not valid. The client application must be marked as 'mobile', or the value must be an absolute URL which matches the registered redirect URI.
The error description reads as if your application is still not marked as mobile app.
I just went to https://apps.dev.microsoft.com/#/appList and created a new application. I have then added the 'Mobile' platform for the application and configured the AppID as api_client_id
and the Application Secret as api_client_secret
in the file onedrive.cfg
. I was able to successfully complete the authorization process.
Microsoft seems to have modified their UI. I will update the README file to match the new process/wordings.
Thanks for the quick response. When I visit https://apps.dev.microsoft.com/#/appList I see the App I created and 'Mobile application' under Platforms.
Yes I had previously made the onedrive.cfg changes as mentioned - btw I previously had to click 'Generate New Password' under Application secrets to create a Password/Public Key.
Hence, in my onedrive.cfg I have the following already but get the error mentioned. api_client_id set to "Client Id (App Id)" i.e. eaa31... api_client_secret set to the value I got when I created the app (just a portion shown now in "Password/Public Key" i.e. Buk...)
Ah, now I see what I have done differently:
I have created my app as a Live SDK application (second Add button).
When I create a "normal" app (first Add button), I can reproduce your problem. Thank you for the hint. I will try to make the authorization process work for "normal" apps, too.
Ah, great. To be honest I don't know the difference between normal and Live SDK and can probably change mine to be the latter kind too. Will try to understand all this better and get back if I still have issues. Thanks, Nik
I have added a link to the README file, which can be used to create a Live SDK application in case the "Add an app" button is missing.
Please try to register an app using this link and tell me, if this works for you.
Thanks..off on holiday now but will look at this when back :-)
Atb, Nik Sent from Samsung Mobile
Hi,
The 'README' link above takes me to https://apps.dev.microsoft.com/?mkt=de-de#/appList/create/sapi which is in German however I changed the link to https://apps.dev.microsoft.com/#/appList/create/sapi and when clicking 'Create Application' I come to a page that does allow me to create a 'Live SDK application' (though clicking on 'Learn more' takes me to a page which says 'This documentation is archived and is not being maintained.')
Originally I'd gone to https://account.live.com/developers/applications which at that time gave me just a single 'Add an app' button. Now after having created a 'Live SDK application' through following the link above I see an additional 'Add an app' button under 'Live SDK applications' (rather than 'My applications')
I guess Microsoft is changing the way all this works but are keeping the original API working for now.
Anyway, having changed onedrive.cfg happily the script does in fact work (note that the portion that uses bash-json-parser failed until I copied that single file in from its separate GitHub project - it wasn't included in the zip I downloaded)
Thanks for your help!
As mentioned originally I was after a script that I could run on a Linux platform to be able to upload a file to the Microsoft Cloud platform (in fact at work we use OneDrive for Business and SharePoint so those are the platforms I'd ultimately want to be able to upload files to). I previously had a curl script for uploading to SharePoint (on premise) which was quite simple e.g.
curl --ntlm --user Nik:Password1 --upload-file testfile.xlsx https://share.mycompany.com/Site/Shared%20Documents/testfile.xlsx
however it looks like the process for uploading a file is now more involved (I guess to reduce the chance of credentials being stolen as they are transmitted over the internet).
Thanks, Nik
Btw I tried to create a 'Live SDK application' (by going to https://apps.dev.microsoft.com/#/appList/create/sapi) using my work OneDrive for Business account but this gives me "There's a temporary problem with the service. Please try again. If you continue to get this message, try again later.". I am able to create a 'regular' app using my work OneDrive for Business account. Hence, an enhancement might be to get this to work with OneDrive for Business. Thanks, Nik
Hi - yes this new script works for me thanks!
I got the error described "AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided." when running onedriveb-authorize but after adding a new key, updating onedriveb.cfg and re-running onedriveb-authorize I was happily able to upload a file.
Atb, Nik
I appreciate your feedback, Nik. Now I think my suggestion not to use 2 years keys was related to this error, so we can try 2 years keys too. I will consider this in the next commit. I have this script in production environment for now.
Hi, today I tried to set up your script myself. Microsoft might have changed their UI again, I was unable to create a "Live SDK Application". Creating a normal mobile application with the Live SDK option checked did not help as well. Console keeps outpuuting the following after ./onedrive-authorize:
{"error":"invalid_request","error_description":"Public clients can't send a client secret."}
Keep up the good work!
@laufi hi, I have successfully made it. here are my steps:
- create apps from here https://apps.dev.microsoft.com/#/appList/create/sapi , name your app as you like, now we call it video-upload for example.
- go to app detail, your url is like https://apps.dev.microsoft.com/?mkt=zh-cn#/application/sapi/00000000xxxxxxxx
- add mobile application platform
- follow the instructions as README.md
now, you can upload your files!
@cnxzcxy Sounds good, will certainly try it!
Cheers!
laufi
@cnxzcxy Works. You rock! Maybe the readme.md could be improved?
@rootik Can you please check, if the script in branch feature/28-converged-applications works for OneDrive for Business, too? It uses the Microsoft Graph API, which might help unifying onedrive-* and onedriveb-*.
Hello, @fkalis I can confirm simple file upload is working with Graph API
./onedrive-upload -d -f Protected README.md
2016-11-23 16:18:59 Acquiring new access token
2016-11-23 16:19:01 Searching for 'Protected' in ''
2016-11-23 16:19:02 api_folder_id is now '01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH'
2016-11-23 16:19:02 Size of README.md is less than or equal to 104857600 bytes, will use simple upload
2016-11-23 16:19:02 Acquiring new access token
2016-11-23 16:19:03 Uploading 'README.md' as 'README.md' into 01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH
Successfully uploaded 'README.md' as 'README.md'
But I have no succsess with chunked upload yet:
./onedrive-upload -d -f Protected largefile.dat
2016-11-23 16:17:20 Acquiring new access token
2016-11-23 16:17:21 Searching for 'Protected' in ''
2016-11-23 16:17:23 api_folder_id is now '01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH'
2016-11-23 16:17:23 Size of largefile.dat is more than 104857600 bytes, will use chunked upload
2016-11-23 16:17:23 Acquiring new access token
2016-11-23 16:17:24 Requesting upload session for 'largefile.dat'
2016-11-23 16:17:24 Uploading 'largefile.dat' as 'largefile.dat' into 01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH
2016-11-23 16:17:28 Acquiring new access token
2016-11-23 16:17:29 Uploading chunk 0 of 'largefile.dat'
2016-11-23 16:17:29 Content-Length: 9830400
2016-11-23 16:17:29 Content-Range: bytes 0-9830399/157286400
2016-11-23 16:17:34 Retrying upload of chunk 0 of 'largefile.dat' (Previous code: 403)
...
...
@rootik I have added a debug output for the upload url. Can you retry the chunked upload and post the upload url?
According the the official documentation, it is not allowed to send the authorization bearer when uploading chunks, which is why I have removed that part from the curl request.
The upload url for OneDrive Personal does no longer contain an access_token, but maybe the upload url for OneDrive for Business still does?
@fkalis now it works. Access token exists in url. This is the output:
./onedrive-upload -d -f Protected largefile.dat
2016-11-24 15:47:53 Acquiring new access token
2016-11-24 15:47:54 Searching for 'Protected' in ''
2016-11-24 15:47:56 api_folder_id is now '01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH'
2016-11-24 15:47:56 Size of largefile.dat is more than 104857600 bytes, will use chunked upload
2016-11-24 15:47:56 Acquiring new access token
2016-11-24 15:47:57 Requesting upload session for 'largefile.dat'
2016-11-24 15:47:58 Uploading 'largefile.dat' as 'largefile.dat' into 01KB37ZVTFUTHRLTSMHZF3LMQ47RFPOJHH
2016-11-24 15:48:00 Upload url is now https://contoso.sharepoint.com:443/personal/rootik_contoso_com/_api/v2.0/drive/root:/Protected:/uploadSession?guid='7b24936e-1d78-43bc-b789-c1aa930ed1d6'&path='~tmp26_largefile.dat'&overwrite=True&rename=False&access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJ...
entire access token and most chunks skipped
2016-11-24 15:49:27 Acquiring new access token
2016-11-24 15:49:29 Uploading chunk 14 of 'largefile.dat'
2016-11-24 15:49:29 Content-Length: 9830400
2016-11-24 15:49:29 Content-Range: bytes 137625600-147455999/157286400
2016-11-24 15:49:34 Upload of chunk 14 of 'largefile.dat' finished (Code: 202)
2016-11-24 15:49:34 Acquiring new access token
2016-11-24 15:49:36 Uploading chunk 15 of 'largefile.dat'
2016-11-24 15:49:36 Content-Length: 9830400
2016-11-24 15:49:36 Content-Range: bytes 147456000-157286399/157286400
2016-11-24 15:49:45 Upload of chunk 15 of 'largefile.dat' finished (Code: 201)
Successfully uploaded 'largefile.dat' as 'largefile.dat'
@rootik Do you see any reasons to keep any of the onedriveb-* files after switching to the Graph API? I have merged
- silent mode
- exponential timeout
from the onedriveb script back into the onedrive script.