Skip to content

Instantly share code, notes, and snippets.

@4ft35t
Last active June 12, 2026 00:45
Show Gist options
  • Select an option

  • Save 4ft35t/f660dc081bbe5ef72844f4bd1cece331 to your computer and use it in GitHub Desktop.

Select an option

Save 4ft35t/f660dc081bbe5ef72844f4bd1cece331 to your computer and use it in GitHub Desktop.
Update access_token for rclone mount no-admin sharepoint. 自动更新 rclone 挂载的无管理员 sharepoint 配置中的 access_token。 rclone 完整配置见 https://www.nodeseek.com/post-743495-1

rclone 挂载的无管理员的 OneDrive,用 xx-my.sharepoint.com 形式的链接访问。

此方法获取的 access_token 有效期只有 6 小时, 需要把 update-token.sh 加入 crontab 定期更新,4 小时一次合适。

The access token has expired. It's valid from '6/10/2026 3:14:06 AM' and to '6/10/2026 9:14:06 AM'.

重要说明

参考链接

'''
修改 url、email 、passwd 三个参数后,运行脚本,自动登陆然后输出 rclone 需要的三个参数
'''
import json
from playwright.sync_api import sync_playwright
url = "https://xx-my.sharepoint.com/my"
email ='xx@xx'
passwd = 'xx'
with sync_playwright() as p:
context = p.chromium.launch_persistent_context(
user_data_dir="playwright_cache", # Folder to save session
headless=True # Open browser window for debugging
)
page = context.new_page()
page.goto(url)
try:
page.fill('input[type="email"]', email, timeout=2000)
page.click('input[type="submit"]')
page.fill('input[type="password"]', passwd)
page.click('input[type="submit"]')
page.click('input[type="submit"]')
except Exception as e:
pass
page.wait_for_url(url)
# get token
driveInfo = page.evaluate("() => { return window._spPageContextInfo && window._spPageContextInfo.driveInfo; }")
if not driveInfo:
print("Failed to retrieve driveInfo.")
output ={'access_token': driveInfo['.driveAccessToken'].split('=', 1)[1],
'drive_id': driveInfo['.driveUrl'].rsplit('/', 1)[1],
'tenant_url': '/'.join(driveInfo['.driveUrl'].split('/', 4)[0:4])
}
print(json.dumps(output))
#!/bin/bash
set -e -u
SRC_DIR=$(dirname "$(readlink -f "$0")")
config_file=~/.config/rclone/rclone.conf
cd "$SRC_DIR"
new_token=$(python3 gettoken.py | jq -r '.access_token')
sed -i "s/v1.eyJ[^\x22]\+/$new_token/" $config_file
# restart rclone to use new config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment