Skip to content

Commit 2eb0880

Browse files
authored
feat(cli): support OIDC device authorization grant for headless login (NVIDIA#2795)
* feat(cli): support OIDC device authorization grant for headless login Closes NVIDIA#2793 Add OAuth 2.0 Device Authorization Grant (RFC 8628) support to the OpenShell CLI's OIDC login flow. When running in a headless environment (OPENSHELL_NO_BROWSER=1) without a client secret configured, the CLI now uses the device code flow instead of the browser-based PKCE flow. The device code flow: - Requests a device code and user code from the IdP's device authorization endpoint - Displays a verification URL and user code to the user - Polls the token endpoint until the user completes authorization or the code expires - Supports slow_down responses per RFC 8628 by increasing the polling interval This implementation: - Extends OidcDiscovery to optionally capture device_authorization_endpoint - Adds oidc_device_code_flow function with proper error handling for all RFC 8628 error codes - Updates gateway add and gateway login to dispatch to device flow when browser is suppressed - Adds comprehensive unit tests for device flow structs and response parsing - Updates gateway authentication documentation to describe the device code fallback Signed-off-by: Jesse Jaggars <[email protected]> * fix(cli): validate OIDC device token responses Signed-off-by: Jesse Jaggars <[email protected]> * fix(cli): add PKCE to OIDC device flow Signed-off-by: Jesse Jaggars <[email protected]> * docs(cli): document PKCE device flow Signed-off-by: Jesse Jaggars <[email protected]> --------- Signed-off-by: Jesse Jaggars <[email protected]>
1 parent 3a16012 commit 2eb0880

5 files changed

Lines changed: 451 additions & 8 deletions

File tree

‎architecture/gateway.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Supported auth modes:
174174
| Plaintext | Local development or a trusted reverse proxy boundary. |
175175
| Unauthenticated local users | Trusted Kubernetes dev or fully trusted proxy deployments only. |
176176
| Cloudflare JWT | Edge-authenticated deployments where Cloudflare Access supplies identity. |
177-
| OIDC | Bearer-token auth for users, with browser PKCE or client credentials login. |
177+
| OIDC | Bearer-token auth for users, with browser or device-code PKCE and client credentials login. |
178178

179179
The CLI persists the scopes requested during OIDC login in gateway metadata and
180180
reuses them when refreshing an access token. This preserves the intended API

‎crates/openshell-cli/src/commands/gateway.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,26 @@ pub async fn gateway_add(
905905
false
906906
}
907907
}
908+
} else if is_browser_suppressed() {
909+
match crate::oidc_auth::oidc_device_code_flow(
910+
issuer,
911+
oidc_client_id,
912+
oidc_audience,
913+
oidc_scopes,
914+
gateway_insecure,
915+
)
916+
.await
917+
{
918+
Ok(bundle) => {
919+
openshell_bootstrap::oidc_token::store_oidc_token(name, &bundle)?;
920+
eprintln!("{} Authenticated via device code", "✓".green().bold());
921+
true
922+
}
923+
Err(e) => {
924+
eprintln!("{} Authentication failed: {e}", "!".yellow());
925+
false
926+
}
927+
}
908928
} else {
909929
match crate::oidc_auth::oidc_browser_auth_flow(
910930
issuer,
@@ -1129,6 +1149,15 @@ pub async fn gateway_login(name: &str, gateway_insecure: bool) -> Result<()> {
11291149
gateway_insecure,
11301150
)
11311151
.await?
1152+
} else if is_browser_suppressed() {
1153+
crate::oidc_auth::oidc_device_code_flow(
1154+
issuer,
1155+
client_id,
1156+
audience,
1157+
scopes,
1158+
gateway_insecure,
1159+
)
1160+
.await?
11321161
} else {
11331162
crate::oidc_auth::oidc_browser_auth_flow(
11341163
issuer,

0 commit comments

Comments
 (0)