-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Problem
Organizations with strict Google Workspace admin policies (admin_policy_enforced) block the "installed" (Desktop) OAuth flow that gws auth login uses. This prevents users in managed Workspace accounts from authenticating, even when they have a valid OAuth client.
The root cause is that gws uses yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect, which binds to a random port. Google identifies this as a Desktop/installed flow pattern, which some orgs block via API Controls.
Error
Access to your account data is restricted by policies within your organization.
Error 400: admin_policy_enforced
Discovery
Through testing, I found that the same org that blocks Desktop OAuth allows Web Application type OAuth clients with a fixed redirect URI. The difference:
| Flow | Redirect URI | Org Policy |
|---|---|---|
Desktop (current gws) |
http://localhost:<random_port> |
BLOCKED |
| Web Application (fixed port) | http://localhost:8080 |
ALLOWED |
Confirmed by creating a Web Application OAuth client with http://localhost:8080 as redirect URI and successfully authenticating with the org account.
Suggested Fix
A 3-line change in the Rust source:
src/auth_commands.rs
- redirect_uris: vec!["http://localhost".to_string()],
+ redirect_uris: vec![format!("http://localhost{}", port.map_or(String::new(), |p| format!(":{p}")))],- yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
+ match port {
+ Some(p) => yup_oauth2::InstalledFlowReturnMethod::HTTPPortRedirect(p),
+ None => yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
+ },CLI interface
gws auth login --port 8080
- When
--portis provided: usesHTTPPortRedirect(port)with fixed redirect URI — compatible with Web Application type OAuth clients - When
--portis omitted: current behavior (random port, Desktop flow) — no breaking change
src/oauth_config.rs
The save_client_config function should also support both "installed" and "web" client types, since users with this org restriction will need to create a Web Application type client instead of Desktop.
Setup for Affected Users
Users with admin_policy_enforced would:
- Create a Web Application (not Desktop) OAuth client in GCP Console
- Set redirect URI to
http://localhost:8080 - Run
gws auth login --port 8080
Environment
- gws v0.18.0
- Managed Google Workspace account
- macOS
yup-oauth2v12 supportsHTTPPortRedirect(u16)already — no dependency changes needed