Web Distributed Authoring and Versioning is an extension of the Hypertext Transfer Protocol that allows clients to perform remote Web content authoring operations.
Update:
2018.06.02 Since the rclone has support to mount the OneDrive for Business without root permission, it’s recommended to use it for more conveniently.
Introduction
If the domain of your office365 account has been verified, you can use the API of OneDrive for Business with some client. See that on my previous post:
http://shui.azurewebsites.net/2017/07/07/onedrive-for-business-cli/
However, many schools don’t verify the domain, and the office365 accounts of these schools can apply online through the Microsoft website
https://products.office.com/en-us/student/office-in-education
When trying the API, these accounts will get the error:
Using application **** is currently not supported for your organization doamin.com because it is in an unmanaged state. An administrator needs to claim ownership of the company by DNS validation of doamin.com before the application *** can be provisioned.
Fortunately, we can mount OneDrive for Business through WebDav, the same way with the official OneDrive UWP on Windows 10. The way of authorising is cookie, not the normal username and password. As far as I know, the Konqueror, a GUI file manager on KDE, and davfs2, a WebDav command line tool, support to mount webdav server with cookie on Linux.
Usage
I will show the operations on Ubuntu 16.04.
Get OD4B Cookie
Login the office365 website. Choose “Stay signed in?” to “YES”, and keep the period of validity longer.
Press F12 or right click–>Inspect element–>Network to capture the traffic.
Open SharePoint or OneDrive app.
1 2 3 4 |
#OD4B https://*****-my.sharepoint.com/_layouts/15/MySite.aspx?MySiteRedirect=AllDocuments #sharepoint https://*****.sharepoint.com/_layouts/15/sharepoint.aspx |
Select a HTTP request include *****.sharepoint.com, you can see the rtFa and FedAuth cookie that are required to authorize.
Get WebDav Link
Open a folder on OD4B website, copy the link on the Address Bar and URL Decode
1 |
https://***-my.sharepoint.com/personal/username_domain_edu/_layouts/15/onedrive.aspx?id=/personal/username_domain_edu/Documents/bookmarks |
Finally, the webdav link of root directory of OD4B:
1 |
https://***-my.sharepoint.com/personal/username_domain_edu/Documents |
Install Davfs2
1 |
sudo apt-get update && sudo apt-get install -y davfs2 |
Modify Davfs2 config
1 2 3 4 |
sudo chmod 777 /etc/davfs2/davfs2.conf echo "use_locks 0" >> /etc/davfs2/davfs2.conf echo "[/home/test]" >> /etc/davfs2/davfs2.conf echo "add_header Cookie rtFa=U5/qsS***UAAAA=;FedAuth=77u/PD9****U1A+" >> /etc/davfs2/davfs2.conf |
Mount OD4B
1 |
sudo /sbin/mount.davfs https://***-my.sharepoint.com/personal/username_domain_edu/Documents/bookmarks /home/test |
Chech Mounting Status
1 |
df |
Upload File
You can operate the mounting folder (/home/test) like local folder.
1 |
cp text.zip /home/test |
Unmount OD4B
1 |
sudo umount /home/test |
Shell Script
For easy use, you can use the simple shell script. If you want to mount multiple accounts, just repeat the operations or run the shell script repeatly.
Cookie Version
1 |
wget https://raw.githubusercontent.com/yulahuyed/test/master/OD4B.sh && bash OD4B.sh |
Auto Login Version
1 |
wget https://raw.githubusercontent.com/yulahuyed/test/autologin/OD4B.sh && bash OD4B.sh |
Docker
You can create a davfs2 image with Docker. The Image need to run with –cap-add SYS_ADMIN –device=/dev/fuse –security-opt apparmor:unconfined or –privileged.
Errors
mount.davfs: Mounting failed. 302 Found
Please make sure the link of OD4B is correct. Solution from #69
Reference linkļ¼
https://unix.stackexchange.com/questions/337329/mount-webdav-on-linux-with-cookie-authentication
https://micreabog.wordpress.com/2017/02/24/using-duplicity-with-microsoft-sharepointonedrive-for-business/
I’m trying to mount OneDrive for business using the method you describe in this article, and getting “mount.davfs: Mounting failed. 302 Found”
Do you know why this happens, or if there is a workaround? Is it due to OAuth? Any help will be greatly appreciated!
Maybe you try with the wrong link of OD4B. You could see the previous comment with the same error.
Yeah I did read the previous comment, but when I tried it that way I get a 403 unauthorized. I think maybe Microsoft has removed support for webdav.
I will try it later. The OneDrive application on the Windows store seems to use the webdav to manage the accounts as well, so it would not remove by Microsoft.
I was able to get it to work! I believe what the issue was is extra data or something mangled in the cookie earlier.
To other people reading this: be sure to read the article very carefully, look at the image where he is looking at the cookie and what exact data is being used. Try the provided auto-login script.
Thanks for the help, this is a great script you have written. Good job!
Thanks for your reply to figure out the reason.
I tried the AutoLogin shell script and got
/sbin/mount.davfs: Mounting failed.
302 Found
I guess my OD4B link was wrong, but I don’t know what is the correct format. My link is like this:
https://***edutw-my.sharepoint.com/personal/***_edu_tw/_layouts/15/onedrive.aspx?id=/personal/***_edu_tw/Documents/
Done. I corrected my link like your script hints, and it works like this:
https://***edutw-my.sharepoint.com/personal/***_edu_tw/Documents/
Thanks a lot for help!!!
Can you tell me the differences between Cookie Version & Auto Login Version in the Shell Script?
And how to undo the change after using shell script?
Many thanks!
Auto Login Version will ask your account/password to capture the cookie by a Python script.
Cookie Version will ask the cookie, captured by yourself on the browser, to authorize.
Remove the change on the config file (davfs2.conf) and unmount to undo the operation.