Skip to content

Commit 810197c

Browse files
authored
Implement FR #2693: Implement OAuth2 Device Authorisation Flow (#3313)
Adds support for Microsoft’s OAuth2 Device Authorisation Flow, enabling the client to authenticate using device and user codes on a second device. This is particularly useful for headless or limited-input environments where interactive browser login is not possible. Includes: - Initiating device code requests and displaying user instructions - Polling token endpoint until user authorises the device or the code expires - Error handling for pending, declined, and expired authorisation states - Countdown display showing remaining authorisation window This feature is enabled via the `use_device_auth` config option
1 parent c91eafb commit 810197c

File tree

7 files changed

+366
-126
lines changed

7 files changed

+366
-126
lines changed

.github/actions/spelling/allow.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ abraunegg
77
accrights
88
accrightslen
99
adamdruppe
10+
ADand
1011
addrepo
12+
Adevice
1113
adr
14+
Agrant
1215
ags
16+
Aietf
1317
aip
1418
alex
1519
alpinelinux
1620
annobin
1721
antix
22+
Aoauth
1823
aothmane
24+
Aparams
1925
apng
2026
archlinux
2127
ARequest
@@ -83,6 +89,7 @@ debian
8389
dechunk
8490
Deepin
8591
deimos
92+
devicecode
8693
devuan
8794
dhparams
8895
dirmask
@@ -108,6 +115,7 @@ eis
108115
ele
109116
endinaness
110117
enduml
118+
Entra
111119
envp
112120
epfd
113121
eselect
@@ -154,13 +162,14 @@ gshared
154162
GVariant
155163
hideonindex
156164
hnsecs
165+
hotmail
157166
howto
158167
hskrieg
159168
htons
160-
ietf
161169
idk
162170
idlol
163171
idup
172+
ietf
164173
ifrom
165174
includedir
166175
ine

config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
## Only upload changes to OneDrive, do not download from cloud.
179179
#upload_only = "false"
180180

181+
## Authenticate using the Microsoft OAuth2 Device Authorisation Flow
182+
#use_device_auth = "true"
183+
181184
## Single Sign-On (SSO) via Intune using the Microsoft Identity Device Broker
182185
#use_intune_sso = "true"
183186

docs/application-config-options.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Before reading this document, please ensure you are running application version
6464
- [threads](#threads)
6565
- [transfer_order](#transfer_order)
6666
- [upload_only](#upload_only)
67+
- [use_device_auth](#use_device_auth)
6768
- [use_intune_sso](#use_intune_sso)
6869
- [use_recycle_bin](#use_recycle_bin)
6970
- [user_agent](#user_agent)
@@ -1018,6 +1019,20 @@ _**CLI Option Use:**_ `--upload-only`
10181019
> [!IMPORTANT]
10191020
> To ensure that data deleted locally remains accessible online, you can use the 'no_remote_delete' option. If you want to delete the data from your local storage after a successful upload to Microsoft OneDrive, you can use the 'remove_source_files' option.
10201021
1022+
### use_device_auth
1023+
_**Description:**_ Enable this option to authenticate using the Microsoft OAuth2 Device Authorisation Flow (`device_code` grant). This flow allows the client to initiate a sign-in process without launching a web browser directly — ideal for headless systems or remote sessions. A short code and URL will be provided for the user to complete authentication via a separate browser-enabled device.
1024+
1025+
_**Value Type:**_ Boolean
1026+
1027+
_**Default Value:**_ False
1028+
1029+
_**Config Example:**_ `use_device_auth = "false"` or `use_device_auth = "true"`
1030+
1031+
_**CLI Option Use:**_ *None - this is a config file option only*
1032+
1033+
> [!IMPORTANT]
1034+
> This option is fully supported for Microsoft Entra ID (Work/School) accounts. For personal Microsoft accounts (e.g., @outlook.com or @hotmail.com), this method of authentication is not supported. Please use the interactive interactive authentication method (default) to authenticate this application.
1035+
10211036
### use_intune_sso
10221037
_**Description:**_ Enable this option to authenticate using Intune Single Sign-On (SSO) via the Microsoft Identity Device Broker over D-Bus. This method is suitable for environments where the system is Intune-enrolled and allows seamless token retrieval without requiring browser interaction.
10231038

docs/usage.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ If you explicitly want to use HTTP/1.1, you can do so by using the `--force-http
336336
> If you continue to use a curl/libcurl version with known HTTP/2 bugs you will experience application runtime issues such as randomly exiting for zero reason or incomplete download/upload of your data.
337337
338338
## First Steps
339+
339340
### Authorise the Application with Your Microsoft OneDrive Account
340341
Once you've installed the application, you'll need to authorise it using your Microsoft OneDrive Account. This can be done by simply running the application without any additional command switches.
341342
@@ -344,6 +345,7 @@ Please be aware that some companies may require you to explicitly add this app t
344345
This client supports the following methods to authenticate the application with Microsoft OneDrive:
345346
* Supports interactive browser-based authentication using OAuth2 and a response URI
346347
* Supports seamless Single Sign-On (SSO) via Intune using the Microsoft Identity Device Broker D-Bus interface
348+
* Supports OAuth2 Device Authorisation Flow for Microsoft Entra ID accounts
347349
348350
#### Interactive Authentication using OAuth2 and a response URI
349351
When you run the application for the first time, you'll be prompted to open a specific URL using your web browser, where you'll need to log in to your Microsoft Account and grant the application permission to access your files. After granting permission to the application, you'll be redirected to a blank page. Simply copy the URI from the blank page and paste it into the application.
@@ -380,6 +382,54 @@ Intune SSO via Microsoft Identity Broker dbus session usage criteria met - will
380382
> [!NOTE]
381383
> The installation and configuration of Intune for your platform is beyond the scope of this documentation.
382384
385+
#### OAuth2 Device Authorisation Flow for Microsoft Entra ID accounts
386+
To use this method of authentication, you must add the following configuration to your 'config' file:
387+
```
388+
use_device_auth = "true"
389+
```
390+
You will be required to open a URL using a web browser, and enter the code that this application presents:
391+
```
392+
Configuring Global Azure AD Endpoints
393+
394+
Authorise this application by visiting:
395+
396+
https://microsoft.com/devicelogin
397+
398+
Enter the following code when prompted: ABCDEFGHI
399+
400+
This code expires at: 2025-Jun-02 15:27:30
401+
```
402+
You will have ~15 minutes before the code expires.
403+
404+
> [!IMPORTANT]
405+
> #### Limitation: OAuth2 Device Authorization Flow and Personal Microsoft Accounts
406+
>
407+
> While the OneDrive Client for Linux fully supports OAuth2 Device Authorisation Flow (`device_code` grant) for **Microsoft Entra ID (Work/School)** accounts, **Microsoft currently does not allow this flow to be used with personal Microsoft accounts (MSA)** unless the application is explicitly authorised by Microsoft.
408+
>
409+
> **Application Configuration Summary:**
410+
>
411+
> - `signInAudience`: `AzureADandPersonalMicrosoftAccount`
412+
> - `allowPublicClient`: `true`
413+
> - Uses Microsoft Identity Platform v2.0 endpoints (`/devicecode`, `/token`, etc.)
414+
> - Microsoft Graph scopes properly defined
415+
>
416+
> Despite this correct configuration, users signing in with a personal Microsoft account will see the following error:
417+
>
418+
> > **"The code you entered has expired. Get a new code from the device you're trying to sign in to and try again."**
419+
>
420+
> This occurs even if the code is entered immediately. Microsoft redirects the user to:
421+
>
422+
> ```
423+
> https://login.live.com/ppsecure/post.srf?username=......
424+
> ```
425+
>
426+
> This behaviour confirms that Microsoft **blocks the `device_code` grant flow for MSA accounts** on unapproved apps.
427+
>
428+
> **Recommendation:**
429+
> If using a personal Microsoft account (e.g., @outlook.com or @hotmail.com), please complete authentication using the interactive authentication method detailed above.
430+
>
431+
> **Further Reading:**
432+
> 📚 [Microsoft Documentation — OAuth 2.0 device authorization grant](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-device-code)
383433
384434
### Display Your Applicable Runtime Configuration
385435
To verify the configuration that the application will use, use the following command:
@@ -1259,7 +1309,7 @@ journalctl --unit=onedrive -f
12591309
#### OneDrive service running as a non-root user via systemd (All Linux Distributions)
12601310
In some instances, it is preferable to run the OneDrive client as a service without the 'root' user. Follow the instructions below to configure the service for your regular user login.
12611311

1262-
1. As the user who will run the service, launch the application in standalone mode, authorize it for use, and verify that synchronization is functioning as expected:
1312+
1. As the user who will run the service, launch the application in standalone mode, authorise it for use, and verify that synchronisation is functioning as expected:
12631313
```text
12641314
onedrive --sync --verbose
12651315
```

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Since forking in early 2018, this client has evolved into a clean re-imagining o
2525
* Supports seamless access to shared folders and files across both OneDrive Personal and OneDrive for Business accounts
2626
* Supports single-tenant and multi-tenant applications
2727
* Supports Intune Single Sign-On (SSO) authentication via the Microsoft Identity Device Broker (D-Bus interface)
28+
* Supports OAuth2 Device Authorisation Flow for Microsoft Entra ID accounts
2829
* Supports national cloud deployments including Microsoft Cloud for US Government, Microsoft Cloud Germany, and Azure/Office 365 operated by VNET in China
2930
* Provides rules for client-side filtering to select data for syncing with Microsoft OneDrive accounts
3031
* Protects against significant data loss on OneDrive after configuration changes

src/config.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ class ApplicationConfig {
420420
// Use authentication via Intune SSO via Microsoft Identity Broker (microsoft-identity-broker) dbus session
421421
boolValues["use_intune_sso"] = false;
422422

423+
// Use authentication via OAuth2 Device Authorisation Flow
424+
boolValues["use_device_auth"] = false;
425+
423426
// EXPAND USERS HOME DIRECTORY
424427
// Determine the users home directory.
425428
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
@@ -1557,6 +1560,7 @@ class ApplicationConfig {
15571560

15581561
// authentication
15591562
addLogEntry("Config option 'use_intune_sso' = " ~ to!string(getValueBool("use_intune_sso")));
1563+
addLogEntry("Config option 'use_device_auth' = " ~ to!string(getValueBool("use_device_auth")));
15601564

15611565
// logging and notifications
15621566
addLogEntry("Config option 'enable_logging' = " ~ to!string(getValueBool("enable_logging")));

0 commit comments

Comments
 (0)