-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathwith_device_flow.py
More file actions
28 lines (19 loc) · 796 Bytes
/
Copy pathwith_device_flow.py
File metadata and controls
28 lines (19 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Connect to SharePoint using device code flow.
Useful for devices or environments without a web browser.
The user authenticates on another device by visiting a URL
and entering the displayed code.
See https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-device-code
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, site_url, tenant
def main():
argparse.ArgumentParser(description="Connect to SharePoint using device code flow").parse_args()
ctx = ClientContext(site_url).with_device_flow(tenant, client_id)
me = ctx.web.current_user.get().execute_query()
print(me.login_name)
web = ctx.web.get().execute_query()
print(web.title)
if __name__ == "__main__":
main()