Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to authenticate sharepoint on 21vianet #932

Open
arrebnac opened this issue Jan 20, 2025 · 1 comment
Open

How to authenticate sharepoint on 21vianet #932

arrebnac opened this issue Jan 20, 2025 · 1 comment
Labels

Comments

@arrebnac
Copy link

I tried to authenticate my Sharepoint on 21vianet with client secret, but it reported '401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/web/getFileByServerRelativePath%28DecodedUrl%3D%27https://galab.sharepoint.cn/:x:/g/EdLtDQIxUHxLj0FuemeleMsBaczbg7-bNKcqyDIyHR5utA%3Fe%3DO04gLy%27%29/%5C%24value'

I have identify the authority url and acquire token url by using the url of "https://login.chinacloudapi.cn/{0}".format(test_tenant) and "https://microsoftgraph.chinacloudapi.cn/.default" according to https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/o365-china-endpoints

Please see my screenshot as below

Image

Could you help me where is my code's problem?

@vgrem
Copy link
Owner

vgrem commented Mar 19, 2025

Greetings,

assuming file url represents a sharing link, consider to utilize ClientContext instead of GraphClient client and get_file_by_guest_url method to return a file:

ctx = ClientContext(test_site_url).with_access_token(acquire_token)
file = ctx.web.get_file_by_guest_url(file_url).execute_query()

In the acquire_token method, the scope needs to be adjusted accordingly to:

scopes = ["https://galab.sharepoint.cn/.default"]

@vgrem vgrem added the question label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants