rclone 配置 OneDrive 和 SharePoint 远程路径

Shell
Foo 2021-11-3

2846 0

觉得我太啰嗦的话可以去读官方的文档 : https://rclone.org/onedrive/

以及其他具体的操作方法(例如上传下载挂载什么的)也还要去看官方的文档。

基本流程

提示在以 “#” 开头的注释里。

# 起一个名字,以后进行操作的时候会以这个名字区分不同路径。
name> foo
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
……
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
# 选择一个存储类型,对于 OneDrive (包含 OneDrive for Business) 和 SharePoint来说,
# 就是 26 那个 “onedrive”。
# 25 那个是 Azure 的存储账户。
Storage> 26
OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
# OAuth 客户端 ID,如果自己有 Microsoft 账户或者是某个 Microsoft 365 订阅的管理员的话,
# 建议参考后面的流程生成一个。
# 留空的话这里就会用 rclone 默认的客户端 ID 和密码。
client_id> 
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
# OAuth 客户端密码,如果你在从 Azure 复制自己的密码时,记得复制的是密码的值而不是 ID。
client_secret> 
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
# OneDrive 的区域,第一个是国际版,第二个是世纪互联版,中间那两个你应该用不上。
region> 1
Edit advanced config?
y) Yes
n) No (default)
# 要编辑高级设置么?
# 通常情况下不需要改默认的设定,所以这里输入 No。
y/n> n
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
# 使用自动配置?

使用自动配置获得 Token

自动配置会在你的浏览器里打开一个 http://127.0.0.1:53682/auth 的网页,如果浏览器没有自动启动的话,你可以在从日志中复制出地址手动打开。

2021/11/03 16:49:51 NOTICE: Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config.
2021/11/03 16:49:51 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=m6E5qq5m6imkYPIbOnzsPQ
2021/11/03 16:49:51 NOTICE: Log in and authorize rclone for access
2021/11/03 16:49:51 NOTICE: Waiting for code...
2021/11/03 16:50:05 NOTICE: Got code

然后转到 Microsoft账户登录页面登录,第一次使用时会提示同意应用。

如果你不是某个订阅的管理员的话,就不会有“代表组织同意”这个选项。

以及如果组织需要审批才能运行域外的应用时,这里的同意会变成“申请审批”。

以及再给一个小提示,如果你是在 VPS 一类的远程服务器上设置的话,可以通过 SSH 的端口转发功能在本地的浏览器上打开授权页面,例如:

$ ssh -L 53682:127.0.0.1:53682 user@hostname

使用手动配置获得 Token

这一步要求你可以打开浏览器的电脑安装有相同版本的 rclone。

如果不使用自动配置的话,下一步会是这样:

For this to work, you will need rclone available on a machine that has
a web browser available.

For more help and alternate methods see: https://rclone.org/remote_setup/

Execute the following on the machine with the web browser (same rclone
version recommended):

    rclone authorize "onedrive" "eyJjbGllbnRfaWQiOiJmNGUwMGM5NS05ZGRkLTQ3M2ItYTlkYS0yZmVjYjQ0YmViYjciLCJjbGllbnRfc2VjcmV0IjoiYmR0N1F+djV5RUt+OHJ0S0FYbHJoenktWnY1Q0ZtV0NGNi1iYSJ9"

Then paste the result.

Enter a string value. Press Enter for the default ("").
config_token> 

把 rclone authorize 开头的那一行复制到你自己的电脑上运行,中间的过程和刚刚的自动配置是相同的。

如果成功的话,终端的输出里会有一场串字母,把它复制下来粘贴到上面 config_token> 的地方。

设置远程目录

Type of connection
Enter a string value. Press Enter for the default ("onedrive").
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
 config_type> 1

最常用到的就是前面三项。

  • 第一项就是你自己的 OneDrive 根目录。
  • 第二项是你组织的 SharePoint 网站首页 (https://组织名称.sharepoint.com
  • 第三项需要你提供你组织中的 SharePoint 的网站名或 URL,例如上面的例子。

补记:注册自己的应用 ID 和机密

需要有一个 Microsoft 账户,可以是个人 / 工作或学校账户。

转到 https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade ,点击上面的“新注册”:

https://fars.ee/7xC8.png

应用的名字和范围可以自己设定(推荐的范围就是第三个 “任何组织目录(任何 Azure AD 目录 - 多租户)中的帐户和个人 Microsoft 帐户(例如,Skype、Xbox)”)以及记得把下面的重定向 URL 类型设置成 Web,地址 设置成 http://localhost:53682/

https://fars.ee/9OQw.png

转到新应用的 API 权限页面,为应用申请必要的权限。(除了图上的这四个以外 rclone 还需要一个 offline_access ,如果已配置权限还是空白的话,点击上面的“添加权限”,然后选择 Microsoft Graph 中的 “委托的权限”):

https://fars.ee/76DG.png

再转到管理页面中的“证书和密码”部分,生成一个机密(在客户端机密里):

https://fars.ee/i3KR.png

复制下来生成的机密的值(不是 ID)和概述中的 应用程序(客户端) ID,这两个分别就是 rclone 需要的 client_secretclient_id

这家伙太懒了,什么也没留下。
最新回复 (0)
    • YiOVE论坛
      2
         
返回