Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(desktop): Continue with Google and Continue with Apple replace Sign in

Dev jacobcd2a9fd2f639
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.md
index 48ba58208..3d2aa3036 100644
--- a/desktop/CLAUDE.md
+++ b/desktop/CLAUDE.md
@@ -143,6 +143,17 @@ The native desktop target uses the CLI for cloud access and SSO tokens:
- **Auth** lives in the CLI. `lib/auth/cli_login.dart` shells out to `harness auth status --json` and
drives `harness login --json` (NDJSON event stream); `cli_link.dart` wraps `harness link create/import/list`.
+ The login screen's way in is two buttons, Continue with Google and Continue with Apple
+ (`widgets/sign_in_provider_button.dart`), on desktop and web alike: `AppNotifier.login(provider)`
+ hands a `SignInProvider` to the sign-in client — `--google`/`--apple` to the CLI, `provider` to the
+ backend's authorize routes in a viewer build — and auth-service opens that account's own sign-in.
+ A caller with no button of its own (`login()` with none) still gets the page's chooser.
+ Each surface signs in as its own auth-service client (backend `SSO_CLIENT_IDS`): the CLI as
+ `harness-cli`, or `harness-desktop` when this app runs it (`--entry-point=desktop`); a viewer
+ build as `auth/sso_client.dart` says (`harness-web` in the browser). ⚠️ A token belongs to the
+ client it was issued to, so the session keeps the client the backend's exchange REPORTS — never
+ the one it asked for, since an older backend exchanges as its configured client and names none
+ — and every refresh names it again (`AuthSession.ssoClientId`, the CLI's `session.json`).
Sign-out owns its CLI process, checks its exit, and terminates it on timeout. `AppNotifier` joins
repeated sign-out requests and blocks another sign-in until credential and connection cleanup
finish; failure offers keyboard-focused Retry sign out. Development fixture disconnects never
diff --git a/desktop/assets/sign-in/apple.svg b/desktop/assets/sign-in/apple.svg
new file mode 100644
index 000000000..839b3cef2
--- /dev/null
+++ b/desktop/assets/sign-in/apple.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 814 1000"><path fill="#FFFFFF" d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z"/></svg>
diff --git a/desktop/assets/sign-in/google.svg b/desktop/assets/sign-in/google.svg
new file mode 100644
index 000000000..8dbd6693d
--- /dev/null
+++ b/desktop/assets/sign-in/google.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18"><path fill="#4285F4" d="M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.717v2.258h2.908c1.702-1.567 2.684-3.874 2.684-6.615z"/><path fill="#34A853" d="M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332A8.997 8.997 0 0 0 9 18z"/><path fill="#FBBC05" d="M3.964 10.71A5.41 5.41 0 0 1 3.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.996 8.996 0 0 0 0 9c0 1.452.348 2.827.957 4.042l3.007-2.332z"/><path fill="#EA4335" d="M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 0 0 .957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z"/></svg>
diff --git a/desktop/integration_test/native_workspace_e2e_test.dart b/desktop/integration_test/native_workspace_e2e_test.dart
index de689212a..c0d7dfeb3 100644
--- a/desktop/integration_test/native_workspace_e2e_test.dart
+++ b/desktop/integration_test/native_workspace_e2e_test.dart
@@ -568,7 +568,7 @@ void main() {
await app.expire();
await tester.pumpAndSettle();
expect(app.allPanes, isEmpty);
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
expect(find.text('Could not sign in'), findsNothing);
await key(tester, LogicalKeyboardKey.enter);
// Restored panes wait for their machines with an indeterminate spinner.
@@ -633,7 +633,7 @@ void main() {
expect(cli.attempts, hasLength(2));
cli.attempts.last.complete();
await tester.pumpAndSettle();
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
await key(tester, LogicalKeyboardKey.enter);
expect(cli.logins, 1);
expect(tester.takeException(), isNull);
diff --git a/desktop/lib/auth/auth_session.dart b/desktop/lib/auth/auth_session.dart
index 255e89379..acc50cf5e 100644
--- a/desktop/lib/auth/auth_session.dart
+++ b/desktop/lib/auth/auth_session.dart
@@ -8,6 +8,7 @@ class AuthSession {
static const _refresh = 'auth_refresh_token';
static const _env = 'auth_autonomous_env';
static const _expiresAt = 'auth_access_token_expires_at';
+ static const _ssoClientId = 'auth_sso_client_id';
AuthSession({LocalKeyValueStore? storage})
: _storage = storage ?? HarnessFileStore.shared;
@@ -19,6 +20,7 @@ class AuthSession {
String? refreshToken,
String autonomousEnv = 'prod',
int? expiresIn,
+ String? ssoClientId,
}) async {
await _storage.write(_access, token);
if (refreshToken != null && refreshToken.isNotEmpty) {
@@ -27,6 +29,12 @@ class AuthSession {
await _storage.delete(_refresh);
}
await _storage.write(_env, autonomousEnv);
+ // Belongs to this sign-in alone: one that names no client must not inherit the last one's.
+ if (ssoClientId != null && ssoClientId.isNotEmpty) {
+ await _storage.write(_ssoClientId, ssoClientId);
+ } else {
+ await _storage.delete(_ssoClientId);
+ }
await _saveExpiry(expiresIn);
}
@@ -49,6 +57,10 @@ class AuthSession {
Future<String?> accessToken() => _storage.read(_access);
Future<String?> refreshToken() => _storage.read(_refresh);
Future<String> autonomousEnv() async => (await _storage.read(_env)) ?? 'prod';
+
+ /// The auth-service client this session was issued to, which a refresh names again. Null is
+ /// the backend's configured one: every session saved before the clients were split.
+ Future<String?> ssoClientId() => _storage.read(_ssoClientId);
Future<DateTime?> accessTokenExpiresAt() async {
final raw = await _storage.read(_expiresAt);
final milliseconds = int.tryParse(raw ?? '');
@@ -74,5 +86,6 @@ class AuthSession {
await _storage.delete(_refresh);
await _storage.delete(_env);
await _storage.delete(_expiresAt);
+ await _storage.delete(_ssoClientId);
}
}
diff --git a/desktop/lib/auth/cli_login.dart b/desktop/lib/auth/cli_login.dart
index a24e6b818..68726ace7 100644
--- a/desktop/lib/auth/cli_login.dart
+++ b/desktop/lib/auth/cli_login.dart
@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import '../core/harness_cli_runner.dart';
import 'phone_sign_in.dart';
import 'sign_in_client.dart';
+import 'sign_in_provider.dart';
class CliAuthStatus {
final bool loggedIn;
@@ -81,9 +82,16 @@ class CliLogin implements SignInClient, PhoneSignInClient {
/// flow. Calls [onAuthorizeUrl] as soon as the CLI reports the SSO page to show, then resolves once
/// the CLI's own loopback callback server completes the flow (or throws on failure/cancellation).
/// The process is killed if [cancel] is called while this is in flight.
+ ///
+ /// [provider] is `--google` or `--apple`. One token, so a CLI that predates the flags ignores it
+ /// like any unknown flag and opens the SSO page's own chooser.
@override
- Future<void> login({required void Function(String url) onAuthorizeUrl}) =>
- _login(const [], onAuthorizeUrl: onAuthorizeUrl);
+ Future<void> login({
+ required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) => _login([
+ if (provider != null) '--${provider.name}',
+ ], onAuthorizeUrl: onAuthorizeUrl);
/// `harness login --qr`: the QR arrives as an event, and so does the question of whose account
/// approved it — answered with a `yes` or `no` line on the process's standard input.
@@ -186,7 +194,7 @@ class CliLogin implements SignInClient, PhoneSignInClient {
if (tooOld) {
throw const PhoneSignInException(
'CLI_TOO_OLD',
- 'This computer\'s Harness CLI is too old to sign in with a phone. Use Sign in, or update Harness.',
+ 'This computer\'s Harness CLI is too old to sign in with a phone. Continue with Google or Apple, or update Harness.',
);
}
if (!gotResult || !success) {
diff --git a/desktop/lib/auth/sign_in_client.dart b/desktop/lib/auth/sign_in_client.dart
index 70c80835c..8a25468bd 100644
--- a/desktop/lib/auth/sign_in_client.dart
+++ b/desktop/lib/auth/sign_in_client.dart
@@ -1,4 +1,5 @@
import 'cli_login.dart';
+import 'sign_in_provider.dart';
/// Whether the app is signed in, and how it signs in — the seam between the two kinds of build.
///
@@ -7,8 +8,12 @@ import 'cli_login.dart';
abstract interface class SignInClient {
Future<CliAuthStatus> checkStatus();
- /// Resolves once signed in; throws on failure or [cancel]. [onAuthorizeUrl] gets the SSO page.
- Future<void> login({required void Function(String url) onAuthorizeUrl});
+ /// Resolves once signed in; throws on failure or [cancel]. [onAuthorizeUrl] gets the SSO page,
+ /// which opens on [provider]'s own sign-in — or, without one, on the page's chooser.
+ Future<void> login({
+ required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
+ });
void cancel();
diff --git a/desktop/lib/auth/sign_in_provider.dart b/desktop/lib/auth/sign_in_provider.dart
new file mode 100644
index 000000000..e3498d99a
--- /dev/null
+++ b/desktop/lib/auth/sign_in_provider.dart
@@ -0,0 +1,13 @@
+/// The account a sign-in goes straight to: the login screen's two buttons, the CLI's `--google`
+/// and `--apple`, the backend's `provider` (`SIGN_IN_PROVIDERS` in `backend/src/lib/sso.ts`).
+///
+/// [name] is the wire form in all three places.
+enum SignInProvider {
+ google('Google'),
+ apple('Apple');
+
+ const SignInProvider(this.label);
+
+ /// How the provider is written for a person.
+ final String label;
+}
diff --git a/desktop/lib/auth/sso_client.dart b/desktop/lib/auth/sso_client.dart
new file mode 100644
index 000000000..e4606a45a
--- /dev/null
+++ b/desktop/lib/auth/sso_client.dart
@@ -0,0 +1,15 @@
+import 'package:flutter/foundation.dart' show kIsWeb;
+
+import '../core/runtime_platform.dart';
+
+/// auth-service's client for the surface this build is (backend `SSO_CLIENT_IDS`): a build that
+/// signs in by itself — the web app, a viewer — names its own, so the sign-in is made as that
+/// surface rather than as the terminal's.
+///
+/// A desktop build with the harness CLI beside it never reads this: the CLI signs in, and names
+/// `harness-desktop` itself when the app tells it who is asking (`--entry-point=desktop`).
+String get ssoClientId {
+ if (kIsWeb) return 'harness-web';
+ if (RuntimePlatform.isIOS || RuntimePlatform.isAndroid) return 'harness-mobile';
+ return 'harness-desktop';
+}
diff --git a/desktop/lib/screens/login_screen.dart b/desktop/lib/screens/login_screen.dart
index 5fc513267..ac16e0809 100644
--- a/desktop/lib/screens/login_screen.dart
+++ b/desktop/lib/screens/login_screen.dart
@@ -5,11 +5,14 @@ import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/services.dart';
+import '../auth/sign_in_provider.dart';
import '../shared/widgets/qr_code_view.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../state/app_state.dart';
import '../widgets/login_fleet_map.dart';
import '../widgets/login_relay_diagram.dart';
+import '../widgets/or_divider.dart';
+import '../widgets/sign_in_provider_button.dart';
import '../widgets/web_download_button.dart';
/// The sign-in screen.
@@ -25,6 +28,10 @@ import '../widgets/web_download_button.dart';
/// middle of a flow, and the reason the button's own spinner was almost never
/// seen. The wait is now a state of the button, so the frame never jumps.
///
+/// The way in is two buttons, Continue with Google and Continue with Apple
+/// ([SignInProviderButton]), as on the Autonomous storefront — not one Sign in
+/// that left the choice to the browser (owner, 2026-10-01).
+///
/// ⚠️ **The SSO page cannot be embedded, and that is not a preference.**
/// `auth.autonomous.ai`'s Google sign-in uses Google's popup-based Identity
/// Services flow — a real popup window that posts its result back to its
@@ -150,13 +157,17 @@ class LoginScreen extends StatelessWidget {
const LoginFleetMap(),
SizedBox(height: gap),
],
- _Action(notifier: notifier, waiting: waiting),
+ _Action(
+ notifier: notifier,
+ waiting: waiting,
+ compact: compact,
+ ),
if (notifier.lastError != null &&
!notifier.sessionExpired) ...[
const SizedBox(height: 16),
_ErrorTile(
message: notifier.lastError!,
- onRetry: notifier.login,
+ onRetry: notifier.retryLogin,
),
],
SizedBox(height: gap),
@@ -261,6 +272,7 @@ class LoginScreen extends StatelessWidget {
child: _Action(
notifier: notifier,
waiting: waiting,
+ compact: compact,
prominent: true,
),
),
@@ -273,7 +285,7 @@ class LoginScreen extends StatelessWidget {
),
child: _ErrorTile(
message: notifier.lastError!,
- onRetry: notifier.login,
+ onRetry: notifier.retryLogin,
),
),
],
@@ -295,21 +307,27 @@ class LoginScreen extends StatelessWidget {
);
}
-/// The button, and what it becomes while the browser is open.
+/// The two buttons, and what they become while the browser is open.
///
-/// One widget for both because they are one control in two states: the label
-/// changes, a spinner replaces the glyph, and Cancel appears beside it. Nothing
-/// moves position, so the wait reads as *this button is working* rather than as
-/// a new screen.
+/// One widget for both because they are one control in two states: the pressed
+/// button's label changes, a spinner replaces its mark, the other steps back,
+/// and Cancel appears below. Nothing moves position, so the wait reads as *this
+/// button is working* rather than as a new screen.
class _Action extends StatefulWidget {
const _Action({
required this.notifier,
required this.waiting,
+ required this.compact,
this.prominent = false,
});
final AppNotifier notifier;
final bool waiting;
+
+ /// A short window: the ways in close up, so the line under them — which is
+ /// where an expired session and a failed sign-out are explained — stays on
+ /// screen at the minimum window.
+ final bool compact;
final bool prominent;
@override
@@ -377,30 +395,39 @@ class _ActionState extends State<_Action> {
final signingOutFailed = notifier.signOutError != null;
return Column(
children: [
- FilledButton.icon(
- style: buttonStyle,
- focusNode: _signInFocus,
- autofocus: true,
- onPressed: signingOutFailed ? notifier.logout : notifier.login,
- icon: Icon(
- signingOutFailed ? AppIcons.logOut : AppIcons.logIn,
- size: grid.AppControl.iconSize,
- ),
- label: Text(signingOutFailed ? 'Retry sign out' : 'Sign in'),
- ),
- // The other way in: a QR a phone already signed in scans and approves. Not on a web page
- // at phone width — that page IS the phone.
- if (notifier.canSignInWithPhone &&
- !signingOutFailed &&
- !(kIsWeb && MediaQuery.sizeOf(context).width < 720)) ...[
- const SizedBox(height: 10),
- OutlinedButton.icon(
- key: const Key('login-scan-with-phone'),
- onPressed: notifier.loginWithPhone,
- icon: const Icon(AppIcons.smartphone, size: 16),
- label: const Text('Scan with your phone'),
+ if (signingOutFailed)
+ FilledButton.icon(
+ style: buttonStyle,
+ focusNode: _signInFocus,
+ autofocus: true,
+ onPressed: notifier.logout,
+ icon: const Icon(AppIcons.logOut, size: grid.AppControl.iconSize),
+ label: const Text('Retry sign out'),
+ )
+ else
+ _waysIn(
+ otherWays: [
+ // The other way in: a QR a phone already signed in scans and approves. Not on a
+ // web page at phone width — that page IS the phone.
+ if (notifier.canSignInWithPhone &&
+ !(kIsWeb && MediaQuery.sizeOf(context).width < 720)) ...[
+ if (!widget.compact) const OrDivider(),
+ OutlinedButton.icon(
+ key: const Key('login-scan-with-phone'),
+ style: widget.compact
+ ? null
+ : OutlinedButton.styleFrom(
+ minimumSize: SignInProviderButton.minimumSize(
+ prominent: widget.prominent,
+ ),
+ ),
+ onPressed: notifier.loginWithPhone,
+ icon: const Icon(AppIcons.smartphone, size: 16),
+ label: const Text('Scan with your phone'),
+ ),
+ ],
+ ],
),
- ],
const SizedBox(height: 12),
Semantics(
liveRegion: signingOutFailed || notifier.sessionExpired,
@@ -485,13 +512,7 @@ class _ActionState extends State<_Action> {
spacing: 8,
alignment: WrapAlignment.center,
children: [
- OutlinedButton(
- onPressed: () {
- notifier.cancelLogin();
- unawaited(notifier.login());
- },
- child: const Text('Use browser instead'),
- ),
+ // Back to the two buttons: that is where the browser's way in is chosen.
TextButton(
onPressed: notifier.cancelLogin,
style: TextButton.styleFrom(
@@ -514,24 +535,29 @@ class _ActionState extends State<_Action> {
(url != null && _copyFailureUrl == url
? 'Couldn’t copy the link. Try opening your browser again.'
: null);
+ final working = notifier.signingOut
+ ? 'Signing out…'
+ : (url == null ? 'Signing in…' : 'Waiting for your browser');
+ // The button the person pressed. A sign-out has none, and neither has a
+ // sign-in started away from these buttons.
+ final pressed = notifier.signingOut ? null : notifier.signInProvider;
return Column(
children: [
- FilledButton.icon(
- style: buttonStyle,
- // Disabled, not hidden: the control the user just pressed has to stay
- // where they left it, saying what it is doing.
- onPressed: null,
- icon: const SizedBox(
- width: grid.AppControl.iconSize,
- height: grid.AppControl.iconSize,
- child: CircularProgressIndicator(strokeWidth: 2),
- ),
- label: Text(
- notifier.signingOut
- ? 'Signing out…'
- : (url == null ? 'Signing in…' : 'Waiting for your browser'),
+ // Disabled, not hidden: the control the user just pressed has to stay
+ // where they left it, saying what it is doing.
+ if (pressed != null)
+ _waysIn(working: (provider: pressed, label: working))
+ else
+ FilledButton.icon(
+ style: buttonStyle,
+ onPressed: null,
+ icon: const SizedBox(
+ width: grid.AppControl.iconSize,
+ height: grid.AppControl.iconSize,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ label: Text(working),
),
- ),
const SizedBox(height: 12),
Semantics(
liveRegion: true,
@@ -594,6 +620,35 @@ class _ActionState extends State<_Action> {
],
);
}
+
+ /// Continue with Google, Continue with Apple, then [otherWays] — all one
+ /// column of rows the same width. [working] is the account whose sign-in is
+ /// in flight and what it says meanwhile; neither can be pressed then.
+ Widget _waysIn({
+ ({SignInProvider provider, String label})? working,
+ List<Widget> otherWays = const [],
+ }) => IntrinsicWidth(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ spacing: 10,
+ children: [
+ for (final provider in SignInProvider.values)
+ SignInProviderButton(
+ provider: provider,
+ prominent: widget.prominent,
+ focusNode: provider == SignInProvider.values.first
+ ? _signInFocus
+ : null,
+ autofocus: provider == SignInProvider.values.first,
+ onPressed: working == null
+ ? () => unawaited(notifier.login(provider))
+ : null,
+ busyLabel: provider == working?.provider ? working?.label : null,
+ ),
+ ...otherWays,
+ ],
+ ),
+ );
}
/// A failure the user can act on.
diff --git a/desktop/lib/shared/theme/app_icons.dart b/desktop/lib/shared/theme/app_icons.dart
index b3b90d906..409c07777 100644
--- a/desktop/lib/shared/theme/app_icons.dart
+++ b/desktop/lib/shared/theme/app_icons.dart
@@ -98,7 +98,6 @@ abstract final class AppIcons {
static const listFilter = LucideIcons.listFilter400;
static const loaderCircle = LucideIcons.loaderCircle400;
static const lock = LucideIcons.lock400;
- static const logIn = LucideIcons.logIn400;
static const logOut = LucideIcons.logOut400;
static const maximize = LucideIcons.maximize400;
static const menu = LucideIcons.menu400;
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 18693033b..3745b071b 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -26,6 +26,7 @@ import '../auth/auth_session.dart';
import '../auth/peer_link_client.dart';
import '../auth/phone_sign_in.dart';
import '../auth/sign_in_client.dart';
+import '../auth/sign_in_provider.dart';
import '../auth/cli_link.dart';
import '../auth/cli_login.dart';
import '../bootstrap/environment_provisioner.dart';
@@ -2125,6 +2126,11 @@ class AppNotifier extends ChangeNotifier {
// attempt, including CLI startup and workspace restoration.
String? pendingAuthorizeUrl;
+ /// The account the sign-in under way went to — which of the login screen's two buttons is
+ /// working — and, once it has failed, the one [retryLogin] goes back to. Null for a sign-in
+ /// that named none: the phone's QR, or one started away from those buttons.
+ SignInProvider? signInProvider;
+
/// Signing in by a phone (`auth/phone_sign_in.dart`): the QR to show while a phone approves it.
String? pendingQrLink;
@@ -4529,7 +4535,9 @@ class AppNotifier extends ChangeNotifier {
}
}
- Future<void> login() async {
+ /// Sign in through the browser, on [provider]'s own sign-in. Without one — a caller with no
+ /// button of its own to name it — the browser opens on the sign-in page's chooser.
+ Future<void> login([SignInProvider? provider]) async {
if (_disposed || signingIn || signingOut || signOutError != null) return;
final wasGuest = isGuest;
final revision = _invalidateAuthWork();
@@ -4538,6 +4546,7 @@ class AppNotifier extends ChangeNotifier {
_lastError = null;
status = AppStatus.bootstrapping;
signingIn = true;
+ signInProvider = provider;
pendingAuthorizeUrl = null;
notifyListeners();
try {
@@ -4546,6 +4555,7 @@ class AppNotifier extends ChangeNotifier {
if (!_authWorkCurrent(revision)) return;
}
await cliLogin.login(
+ provider: provider,
onAuthorizeUrl: (url) {
if (!_authWorkCurrent(revision)) return;
if (pendingAuthorizeUrl == url) return;
@@ -4599,6 +4609,9 @@ class AppNotifier extends ChangeNotifier {
if (_authWorkCurrent(revision)) notifyListeners();
}
+ /// The failed sign-in again, to the account the person chose the first time.
+ Future<void> retryLogin() => login(signInProvider);
+
/// Sign in by a QR a signed-in phone approves, then a yes here to the account it names.
Future<void> loginWithPhone() async {
final client = cliLogin;
@@ -4611,6 +4624,7 @@ class AppNotifier extends ChangeNotifier {
_lastError = null;
status = AppStatus.bootstrapping;
signingIn = true;
+ signInProvider = null;
pendingAuthorizeUrl = null;
_clearPhoneSignIn();
notifyListeners();
diff --git a/desktop/lib/viewer/browser_login.dart b/desktop/lib/viewer/browser_login.dart
index 7eeae5de6..70ea338e9 100644
--- a/desktop/lib/viewer/browser_login.dart
+++ b/desktop/lib/viewer/browser_login.dart
@@ -4,6 +4,7 @@ import 'dart:convert';
import '../auth/cli_login.dart' show CliAuthStatus;
import '../auth/phone_sign_in.dart';
import '../auth/sign_in_client.dart';
+import '../auth/sign_in_provider.dart';
import '../core/browser_label.dart';
import 'direct_auth.dart';
import 'qr_sign_in.dart';
@@ -129,6 +130,7 @@ class BrowserLogin implements SignInClient, PhoneSignInClient {
@override
Future<void> login({
required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
}) async {
cancel();
final revision = _revision;
@@ -139,8 +141,8 @@ class BrowserLogin implements SignInClient, PhoneSignInClient {
// loopback listener. The hosted web endpoint only accepts configured
// origins and otherwise returns the production site's callback.
final start = await (_isLoopback(location)
- ? auth.api.authorizeNative('$origin$callbackPath')
- : auth.api.authorizeWeb(origin));
+ ? auth.api.authorizeNative('$origin$callbackPath', provider: provider)
+ : auth.api.authorizeWeb(origin, provider: provider));
_requireCurrent(revision);
final authorize = Uri.tryParse(start.authorizeUrl);
final redirect = Uri.tryParse(
diff --git a/desktop/lib/viewer/direct_auth.dart b/desktop/lib/viewer/direct_auth.dart
index 02033f3cd..408737eaa 100644
--- a/desktop/lib/viewer/direct_auth.dart
+++ b/desktop/lib/viewer/direct_auth.dart
@@ -49,6 +49,7 @@ class DirectAuth implements AccessTokenSource {
refreshToken: tokens.refreshToken,
autonomousEnv: tokens.autonomousEnv ?? api.config.autonomousEnv,
expiresIn: tokens.expiresIn,
+ ssoClientId: tokens.clientId,
);
// Cancel can land during a disk write. These writes are serialized, so
// clearing this incomplete login cannot erase a newer queued login.
@@ -130,6 +131,7 @@ class DirectAuth implements AccessTokenSource {
final tokens = await api.refresh(
refreshToken,
autonomousEnv: autonomousEnv,
+ clientId: await session.ssoClientId(),
);
_requireCurrent(revision);
await _write(
diff --git a/desktop/lib/viewer/direct_auth_api.dart b/desktop/lib/viewer/direct_auth_api.dart
index 79decfbe4..ef38c343c 100644
--- a/desktop/lib/viewer/direct_auth_api.dart
+++ b/desktop/lib/viewer/direct_auth_api.dart
@@ -2,6 +2,8 @@ import 'package:dio/dio.dart';
import '../api/api_client.dart';
import '../api/access_token_source.dart';
+import '../auth/sign_in_provider.dart';
+import '../auth/sso_client.dart';
import '../core/config.dart';
import '../logging/http_log.dart';
@@ -26,6 +28,7 @@ class IssuedTokens {
this.refreshToken,
this.expiresIn,
this.autonomousEnv,
+ this.clientId,
});
final String token;
@@ -35,16 +38,23 @@ class IssuedTokens {
final int? expiresIn;
final String? autonomousEnv;
+ /// The auth-service client an exchange issued these to, which every refresh must name again.
+ /// Null is the backend's configured one — and what a backend from before the clients were
+ /// split answers, so this is kept as answered, never assumed from what was asked for.
+ final String? clientId;
+
static IssuedTokens? fromData(Object? data) {
if (data is! Map) return null;
final token = data['token'], refresh = data['refreshToken'];
final expiresIn = data['expiresIn'], env = data['autonomousEnv'];
+ final clientId = data['clientId'];
if (token is! String || token.isEmpty) return null;
return IssuedTokens(
token: token,
refreshToken: refresh is String && refresh.isNotEmpty ? refresh : null,
expiresIn: expiresIn is int && expiresIn > 0 ? expiresIn : null,
autonomousEnv: env is String ? env : null,
+ clientId: clientId is String && clientId.isNotEmpty ? clientId : null,
);
}
}
@@ -53,8 +63,9 @@ class IssuedTokens {
/// calls them (cli.ts `loginCommand`, authSession.ts `refreshRequest`). No bearer rides these:
/// they are how one is got.
class DirectAuthApi {
- DirectAuthApi({required this.config, Dio? dio})
- : _dio =
+ DirectAuthApi({required this.config, Dio? dio, String? clientId})
+ : clientId = clientId ?? ssoClientId,
+ _dio =
dio ??
attachHttpLog(
Dio(
@@ -68,21 +79,46 @@ class DirectAuthApi {
);
final AppConfig config;
+
+ /// The auth-service client this build signs in as (`auth/sso_client.dart`).
+ final String clientId;
final Dio _dio;
static const _unavailable =
'Could not renew your sign-in. That is usually the sign-in service having a moment — '
'if it keeps happening, sign out and sign in again.';
+ /// [provider] is the account the SSO page opens on; without one it is the page's own chooser.
Future<({String authorizeUrl, String tx})> authorizeNative(
- String redirectUri,
+ String redirectUri, {
+ SignInProvider? provider,
+ }) => _authorize('/api/auth/authorize-native', {
+ 'redirectUri': redirectUri,
+ }, provider);
+
+ Future<({String authorizeUrl, String tx})> authorizeWeb(
+ String origin, {
+ SignInProvider? provider,
+ }) => _authorize('/api/auth/authorize', {
+ 'origin': origin,
+ 'next': '/',
+ }, provider);
+
+ Future<({String authorizeUrl, String tx})> _authorize(
+ String path,
+ Map<String, Object?> body,
+ SignInProvider? provider,
) async {
final data = unwrapApiResponse(
await _dio.post(
- '/api/auth/authorize-native',
+ path,
data: {
- 'redirectUri': redirectUri,
+ ...body,
'autonomousEnv': config.autonomousEnv,
+ // The surface asking, as auth-service knows it. What the tokens are actually issued
+ // to comes back from the exchange ([IssuedTokens.clientId]).
+ 'clientId': clientId,
+ if (provider != null) 'provider': provider.name,
},
),
);
@@ -93,28 +129,21 @@ class DirectAuthApi {
'The server did not return a sign-in page.',
);
}
- return (authorizeUrl: url, tx: tx);
+ return (authorizeUrl: _openingOn(url, provider), tx: tx);
}
- Future<({String authorizeUrl, String tx})> authorizeWeb(String origin) async {
- final data = unwrapApiResponse(
- await _dio.post(
- '/api/auth/authorize',
- data: {
- 'origin': origin,
- 'next': '/',
- 'autonomousEnv': config.autonomousEnv,
- },
- ),
- );
- final url = data is Map ? data['authorizeUrl'] : null;
- final tx = data is Map ? data['tx'] : null;
- if (url is! String || url.isEmpty || tx is! String || tx.isEmpty) {
- throw const DirectAuthException(
- 'The server did not return a sign-in page.',
- );
- }
- return (authorizeUrl: url, tx: tx);
+ /// [authorizeUrl], naming [provider]. The backend writes it into the page it hands back — but
+ /// only one that knows the field does, and this build reaches people before the backend is
+ /// redeployed. It is the browser's to carry and changes nothing the backend holds (state,
+ /// PKCE, client), so it is set here as well.
+ static String _openingOn(String authorizeUrl, SignInProvider? provider) {
+ final uri = Uri.tryParse(authorizeUrl);
+ if (provider == null || uri == null) return authorizeUrl;
+ return uri
+ .replace(
+ queryParameters: {...uri.queryParameters, 'provider': provider.name},
+ )
+ .toString();
}
Future<IssuedTokens> exchange({
@@ -180,15 +209,23 @@ class DirectAuthApi {
/// `REFRESH_TOKEN_INVALID` means the session is dead. An unusable refresh token and a real outage
/// both come back as the same 503, and reading that as dead would delete a refresh token nothing
/// can bring back — on a blip.
+ ///
+ /// [clientId] is the client the session was issued to ([IssuedTokens.clientId]): a refresh
+ /// under any other is refused.
Future<IssuedTokens> refresh(
String refreshToken, {
required String autonomousEnv,
+ String? clientId,
}) async {
final Response<dynamic> res;
try {
res = await _dio.post(
'/api/auth/refresh',
- data: {'refreshToken': refreshToken, 'autonomousEnv': autonomousEnv},
+ data: {
+ 'refreshToken': refreshToken,
+ 'autonomousEnv': autonomousEnv,
+ 'clientId': ?clientId,
+ },
);
} on DioException {
throw const DirectAuthException(_unavailable);
diff --git a/desktop/lib/viewer/direct_login_native.dart b/desktop/lib/viewer/direct_login_native.dart
index e9d02c67b..ae033cf03 100644
--- a/desktop/lib/viewer/direct_login_native.dart
+++ b/desktop/lib/viewer/direct_login_native.dart
@@ -4,6 +4,7 @@ import 'dart:io';
import '../auth/cli_login.dart';
import '../auth/phone_sign_in.dart';
import '../auth/sign_in_client.dart';
+import '../auth/sign_in_provider.dart';
import '../core/local_hostname.dart';
import 'direct_auth.dart';
import 'direct_auth_api.dart';
@@ -30,6 +31,7 @@ class DirectLogin implements SignInClient, PhoneSignInClient {
@override
Future<void> login({
required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
}) async {
cancel();
final revision = _loginRevision;
@@ -40,6 +42,7 @@ class DirectLogin implements SignInClient, PhoneSignInClient {
callback = _pending = _LoopbackCallback(server);
final start = await auth.api.authorizeNative(
'http://127.0.0.1:${server.port}/callback',
+ provider: provider,
);
_requireCurrent(revision);
onAuthorizeUrl(start.authorizeUrl);
diff --git a/desktop/lib/widgets/or_divider.dart b/desktop/lib/widgets/or_divider.dart
new file mode 100644
index 000000000..570449d33
--- /dev/null
+++ b/desktop/lib/widgets/or_divider.dart
@@ -0,0 +1,37 @@
+import 'package:flutter/material.dart';
+
+import '../shared/theme/app_theme.dart' as grid;
+
+/// A hairline with OR in the middle of it: what follows is another way to do the same thing,
+/// not a second step. The login screen's, between the two accounts and the phone's QR, as on the
+/// Autonomous storefront's sign-in.
+class OrDivider extends StatelessWidget {
+ const OrDivider({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ final line = Expanded(
+ child: Divider(height: 1, color: grid.AppPalette.divider),
+ );
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 2),
+ child: Row(
+ children: [
+ line,
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: Text(
+ 'OR',
+ style: Theme.of(context).textTheme.labelSmall?.copyWith(
+ color: grid.AppPalette.textFaint,
+ letterSpacing: .8,
+ ),
+ ),
+ ),
+ line,
+ ],
+ ),
+ );
+ }
+}
diff --git a/desktop/lib/widgets/sign_in_provider_button.dart b/desktop/lib/widgets/sign_in_provider_button.dart
new file mode 100644
index 000000000..50a29f02f
--- /dev/null
+++ b/desktop/lib/widgets/sign_in_provider_button.dart
@@ -0,0 +1,139 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_svg/flutter_svg.dart';
+
+import '../auth/sign_in_provider.dart';
+import '../shared/theme/app_theme.dart' as grid;
+
+/// One of the login screen's two ways in: "Continue with Google", "Continue with Apple".
+///
+/// Each wears its provider's own colours rather than the app's accent — Google's white with its
+/// four-colour mark, Apple's black with a white one — because that is how a person recognises
+/// them, and how the Autonomous storefront's sign-in already shows them. The shape and the type
+/// stay the app's.
+class SignInProviderButton extends StatelessWidget {
+ const SignInProviderButton({
+ super.key,
+ required this.provider,
+ required this.onPressed,
+ this.busyLabel,
+ this.prominent = false,
+ this.focusNode,
+ this.autofocus = false,
+ });
+
+ final SignInProvider provider;
+
+ /// Null while a sign-in is in flight, on this button or on the other.
+ final VoidCallback? onPressed;
+
+ /// What this button says while ITS sign-in is in flight; a spinner takes the mark's place.
+ /// Disabled without one is the other button's sign-in, and this one dims.
+ final String? busyLabel;
+
+ /// The web page's scale: its sign-in is the page's one call to action, and at
+ /// phone width a thumb's target.
+ final bool prominent;
+ final FocusNode? focusNode;
+ final bool autofocus;
+
+ static const double _markSize = 18;
+
+ /// Every way in shares it — the two accounts and whatever is offered beside them — so they
+ /// read as one control in rows of one size.
+ static Size minimumSize({required bool prominent}) => prominent
+ ? const Size(320, 56)
+ : Size(280, grid.AppControl.heightFieldScaled);
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ final look = _look(provider);
+ final busy = busyLabel != null;
+ return Opacity(
+ // The button that is working stays itself; only the one that cannot be pressed steps back.
+ opacity: onPressed == null && !busy ? .5 : 1,
+ child: FilledButton(
+ key: Key('login-continue-${provider.name}'),
+ focusNode: focusNode,
+ autofocus: autofocus,
+ onPressed: onPressed,
+ style:
+ FilledButton.styleFrom(
+ backgroundColor: look.fill,
+ foregroundColor: look.ink,
+ disabledBackgroundColor: look.fill,
+ disabledForegroundColor: look.ink,
+ // ⚠️ One rim in every state, focus included. The first button holds the
+ // screen's focus at rest (Enter signs in), so anything focus draws is drawn
+ // ALWAYS — and a ring on one of the pair made it read as the larger button
+ // (owner, 2026-10-01).
+ side: BorderSide(color: look.rim),
+ minimumSize: minimumSize(prominent: prominent),
+ textStyle: prominent ? grid.AppType.heading() : null,
+ ).copyWith(
+ // For the same reason, no focus wash: Material's greyed the white fill.
+ overlayColor: WidgetStateProperty.resolveWith(
+ (states) => look.ink.withValues(
+ alpha: states.contains(WidgetState.pressed)
+ ? .12
+ : states.contains(WidgetState.hovered)
+ ? .08
+ : 0,
+ ),
+ ),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox.square(
+ dimension: _markSize,
+ child: busy
+ ? CircularProgressIndicator(strokeWidth: 2, color: look.ink)
+ : _mark(look),
+ ),
+ const SizedBox(width: 10),
+ Flexible(
+ child: Text(
+ busyLabel ?? 'Continue with ${provider.label}',
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _mark(_ProviderLook look) => ExcludeSemantics(
+ child: SvgPicture.asset(
+ 'assets/sign-in/${provider.name}.svg',
+ width: _markSize,
+ height: _markSize,
+ // Google's mark is its four colours; Apple's is one shape in the button's ink.
+ colorFilter: look.tintMark
+ ? ColorFilter.mode(look.ink, BlendMode.srcIn)
+ : null,
+ ),
+ );
+}
+
+/// A provider's own colours. Not theme tokens: they are the providers' brands, the same in light
+/// and dark — except the rim, which each wears only on the card it would otherwise melt into:
+/// Google's white on a light one, Apple's black on a dark one. Where the fill already stands
+/// apart the rim is the fill's own colour, so neither button looks a line larger than the other.
+typedef _ProviderLook = ({Color fill, Color ink, Color rim, bool tintMark});
+
+_ProviderLook _look(SignInProvider provider) => switch (provider) {
+ SignInProvider.google => (
+ fill: Colors.white,
+ ink: const Color(0xFF1F1F1F),
+ rim: grid.AppTheme.pick(const Color(0xFFDADCE0), Colors.white),
+ tintMark: false,
+ ),
+ SignInProvider.apple => (
+ fill: Colors.black,
+ ink: Colors.white,
+ rim: grid.AppTheme.pick(Colors.black, const Color(0x3DFFFFFF)),
+ tintMark: true,
+ ),
+};
diff --git a/desktop/pubspec.yaml b/desktop/pubspec.yaml
index ba278c9dc..6c7216e42 100644
--- a/desktop/pubspec.yaml
+++ b/desktop/pubspec.yaml
@@ -147,6 +147,8 @@ flutter:
- assets/models.png
- assets/model-icons/
- assets/octicons/
+ # The marks on the login screen's two buttons (`widgets/sign_in_provider_button.dart`).
+ - assets/sign-in/
- assets/harness_device_studio.jpg
- assets/harness_store_card.jpg
- assets/swarm-wallpapers/
diff --git a/desktop/test/boot_flow_widget_test.dart b/desktop/test/boot_flow_widget_test.dart
index e9f93466b..074f766c3 100644
--- a/desktop/test/boot_flow_widget_test.dart
+++ b/desktop/test/boot_flow_widget_test.dart
@@ -2,7 +2,6 @@ import 'support/resource_picker.dart';
import 'support/workspace_tools.dart';
import 'swarm_interactions_test.dart' show chord;
-import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/services.dart';
import 'dart:async';
@@ -546,8 +545,8 @@ void main() {
// The card leads with what the app does for you, not with its own name —
// the wordmark left when the screen stopped being a logo over a button.
expect(find.text('Your agents, wherever they run'), findsOneWidget);
- expect(find.text('Sign in'), findsOneWidget);
- expect(find.byIcon(AppIcons.logIn), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
+ expect(find.text('Continue with Apple'), findsOneWidget);
});
testWidgets('bootstrapping shows branded startup screen (pre-login)', (
@@ -569,7 +568,7 @@ void main() {
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('Opening your workspace'), findsOneWidget);
expect(find.text('Opening Harness…'), findsOneWidget);
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
});
testWidgets('live pre-flight has its own quiet screen', (tester) async {
@@ -629,7 +628,7 @@ void main() {
expect(app.status, AppStatus.authenticated);
expect(app.isGuest, isTrue);
// …and the desk is what is on screen, not the sign-in.
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
app.dispose();
},
);
@@ -745,7 +744,7 @@ void main() {
expect(app.status, AppStatus.authenticated);
expect(app.isGuest, isTrue);
// …on the desk, not in front of it.
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
await tester.pumpWidget(const SizedBox());
app.dispose();
},
@@ -871,14 +870,14 @@ void main() {
);
await tester.pump();
expect(find.byType(BootstrappingScreen), findsOneWidget);
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
app.status = AppStatus.unauthenticated;
app.notifyListeners();
await tester.pump();
expect(find.byType(BootstrappingScreen), findsNothing);
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
});
testWidgets(
diff --git a/desktop/test/browser_login_test.dart b/desktop/test/browser_login_test.dart
index c0c2aa62d..5d5bfe24a 100644
--- a/desktop/test/browser_login_test.dart
+++ b/desktop/test/browser_login_test.dart
@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/local_key_value_store.dart';
import 'package:harness/viewer/browser_login.dart';
@@ -36,17 +37,24 @@ class _Api extends DirectAuthApi {
final requests = <({String code, String state, String tx})>[];
String? origin;
String? nativeRedirect;
+ SignInProvider? provider;
@override
Future<({String authorizeUrl, String tx})> authorizeNative(
- String redirectUri,
- ) {
+ String redirectUri, {
+ SignInProvider? provider,
+ }) {
nativeRedirect = redirectUri;
+ this.provider = provider;
return authorization.future;
}
@override
- Future<({String authorizeUrl, String tx})> authorizeWeb(String origin) {
+ Future<({String authorizeUrl, String tx})> authorizeWeb(
+ String origin, {
+ SignInProvider? provider,
+ }) {
this.origin = origin;
+ this.provider = provider;
return authorization.future;
}
@@ -174,7 +182,10 @@ void main() {
'authorization stays in this tab and cancellation discards its transaction',
() async {
String? opened;
- final pending = login.login(onAuthorizeUrl: (url) => opened = url);
+ final pending = login.login(
+ onAuthorizeUrl: (url) => opened = url,
+ provider: SignInProvider.apple,
+ );
final cancelled = expectLater(
pending,
throwsA(isA<DirectAuthException>()),
@@ -186,6 +197,8 @@ void main() {
api.authorization.complete((authorizeUrl: url, tx: 'transaction'));
await Future<void>.delayed(Duration.zero);
expect(api.origin, 'https://harness.example');
+ // The button the person pressed reaches the backend with the request.
+ expect(api.provider, SignInProvider.apple);
expect(api.nativeRedirect, isNull);
expect(opened, url);
expect(jsonDecode(browser.transaction!)['tx'], 'transaction');
diff --git a/desktop/test/cli_login_test.dart b/desktop/test/cli_login_test.dart
index 23c10d9b1..cca5907f9 100644
--- a/desktop/test/cli_login_test.dart
+++ b/desktop/test/cli_login_test.dart
@@ -4,14 +4,26 @@ import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/harness_cli_runner.dart';
class _Runner extends HarnessCliRunner {
+ _Runner({this.method = const []});
+
+ /// The flag naming how to sign in (`--google`, `--apple`), when the test's sign-in names one.
+ final List<String> method;
final starts = <Completer<Process>>[];
@override
Future<Process> start(List<String> arguments) {
- // The entry point rides along so login tracking can tell an app sign-in from a terminal one.
- expect(arguments, ['login', '--force', '--json', '--entry-point=desktop']);
+ // The entry point rides along: login tracking tells an app sign-in from a terminal one by
+ // it, and the CLI signs in as the desktop app's own auth-service client because of it.
+ expect(arguments, [
+ 'login',
+ '--force',
+ '--json',
+ ...method,
+ '--entry-point=desktop',
+ ]);
final start = Completer<Process>();
starts.add(start);
return start.future;
@@ -117,6 +129,28 @@ void main() {
},
);
+ for (final provider in SignInProvider.values) {
+ test(
+ '${provider.label} is one flag to the CLI, and its page still arrives',
+ () async {
+ final runner = _Runner(method: ['--${provider.name}']);
+ final cli = CliLogin(runner: runner);
+ final urls = <String>[];
+ final login = cli.login(onAuthorizeUrl: urls.add, provider: provider);
+ final process = _Process();
+ process.emit({
+ 'type': 'authorize_url',
+ 'url': 'https://auth.example/page',
+ });
+ process.emit({'type': 'result', 'status': 'success'});
+ runner.starts.single.complete(process);
+ process.finish();
+ await login;
+ expect(urls, ['https://auth.example/page']);
+ },
+ );
+ }
+
test(
'cancel while the CLI starts ignores its late URL and stops that process',
() async {
diff --git a/desktop/test/desktop_account_transition_test.dart b/desktop/test/desktop_account_transition_test.dart
index 6fe9d4b16..d121b6a00 100644
--- a/desktop/test/desktop_account_transition_test.dart
+++ b/desktop/test/desktop_account_transition_test.dart
@@ -5,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/models.dart';
import 'package:harness/state/app_state.dart';
@@ -22,7 +23,10 @@ class _Login extends CliLogin {
Future<void> logout() async {}
@override
- Future<void> login({required void Function(String) onAuthorizeUrl}) async {
+ Future<void> login({
+ required void Function(String) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {
logins++;
await pending?.future;
if (fail) throw StateError('Fixture sign-in failed.');
diff --git a/desktop/test/direct_auth_api_test.dart b/desktop/test/direct_auth_api_test.dart
new file mode 100644
index 000000000..cc82c9016
--- /dev/null
+++ b/desktop/test/direct_auth_api_test.dart
@@ -0,0 +1,137 @@
+import 'dart:convert';
+import 'dart:typed_data';
+
+import 'package:dio/dio.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/sign_in_provider.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/viewer/direct_auth_api.dart';
+
+/// Answers every request with [reply] and remembers what was sent.
+class _Backend implements HttpClientAdapter {
+ Map<String, Object?> reply = {
+ 'success': true,
+ 'data': {'authorizeUrl': 'https://sso.example/authorize', 'tx': 'tx-1'},
+ };
+ final sent = <({String path, Map<String, Object?> body})>[];
+
+ @override
+ Future<ResponseBody> fetch(
+ RequestOptions options,
+ Stream<Uint8List>? requestStream,
+ Future<void>? cancelFuture,
+ ) async {
+ sent.add((
+ path: options.path,
+ body: Map<String, Object?>.from(options.data as Map),
+ ));
+ return ResponseBody.fromString(
+ jsonEncode(reply),
+ 200,
+ headers: {
+ Headers.contentTypeHeader: [Headers.jsonContentType],
+ },
+ );
+ }
+
+ @override
+ void close({bool force = false}) {}
+}
+
+/// What a build that signs in by itself — the web app, a viewer — tells the backend: which
+/// auth-service client it is, which account the person chose, and, on a refresh, which client its
+/// session was issued to.
+void main() {
+ late _Backend backend;
+ late DirectAuthApi api;
+
+ setUp(() {
+ backend = _Backend();
+ api = DirectAuthApi(
+ config: AppConfig.dev,
+ clientId: 'harness-web',
+ dio: Dio(BaseOptions(baseUrl: 'https://h.invalid'))
+ ..httpClientAdapter = backend,
+ );
+ });
+
+ test(
+ 'a sign-in names this surface\'s client and the account chosen',
+ () async {
+ final web = await api.authorizeWeb(
+ 'https://harness.example',
+ provider: SignInProvider.google,
+ );
+ // This backend's page does not name the account (one from before `provider`): the page
+ // the browser is sent to names it all the same.
+ expect(web.authorizeUrl, 'https://sso.example/authorize?provider=google');
+ expect(backend.sent.single.path, '/api/auth/authorize');
+ expect(backend.sent.single.body, {
+ 'origin': 'https://harness.example',
+ 'next': '/',
+ 'autonomousEnv': AppConfig.dev.autonomousEnv,
+ 'clientId': 'harness-web',
+ 'provider': 'google',
+ });
+
+ await api.authorizeNative(
+ 'http://127.0.0.1:5000/callback',
+ provider: SignInProvider.apple,
+ );
+ expect(backend.sent.last.path, '/api/auth/authorize-native');
+ expect(backend.sent.last.body, {
+ 'redirectUri': 'http://127.0.0.1:5000/callback',
+ 'autonomousEnv': AppConfig.dev.autonomousEnv,
+ 'clientId': 'harness-web',
+ 'provider': 'apple',
+ });
+ },
+ );
+
+ test(
+ 'no account chosen names none: the sign-in page\'s own chooser',
+ () async {
+ final page = await api.authorizeNative('http://127.0.0.1:5000/callback');
+ expect(page.authorizeUrl, 'https://sso.example/authorize');
+ expect(backend.sent.single.body.containsKey('provider'), isFalse);
+ expect(backend.sent.single.body['clientId'], 'harness-web');
+ },
+ );
+
+ test('the exchange says which client the tokens were issued to', () async {
+ backend.reply = {
+ 'success': true,
+ 'data': {'token': 'access', 'clientId': 'harness-web'},
+ };
+ final issued = await api.exchange(code: 'c', state: 's', tx: 't');
+ expect(issued.clientId, 'harness-web');
+
+ // A backend from before the clients were split names none, whatever was asked for.
+ backend.reply = {
+ 'success': true,
+ 'data': {'token': 'access'},
+ };
+ expect(
+ (await api.exchange(code: 'c', state: 's', tx: 't')).clientId,
+ isNull,
+ );
+ });
+
+ test('a refresh names the session\'s client, or none', () async {
+ backend.reply = {
+ 'success': true,
+ 'data': {'token': 'renewed'},
+ };
+ await api.refresh('r1', autonomousEnv: 'prod', clientId: 'harness-web');
+ expect(backend.sent.single.body, {
+ 'refreshToken': 'r1',
+ 'autonomousEnv': 'prod',
+ 'clientId': 'harness-web',
+ });
+ await api.refresh('r1', autonomousEnv: 'prod');
+ expect(backend.sent.last.body, {
+ 'refreshToken': 'r1',
+ 'autonomousEnv': 'prod',
+ });
+ });
+}
diff --git a/desktop/test/login_screen_phone_test.dart b/desktop/test/login_screen_phone_test.dart
index 2bf55af54..9bdbb65ca 100644
--- a/desktop/test/login_screen_phone_test.dart
+++ b/desktop/test/login_screen_phone_test.dart
@@ -8,10 +8,12 @@ import 'package:harness/app_shell.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
import 'package:harness/auth/sign_in_client.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/screens/login_screen.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/state/app_state.dart';
+import 'package:harness/widgets/or_divider.dart';
/// The login screen's second way in: a QR a signed-in phone approves, then a yes here to the
/// account that approved it.
@@ -86,6 +88,14 @@ Widget _host(AppNotifier app) => MaterialApp(
),
);
+/// [_host] says the window is 700 tall while the test surface is 600, so the last way in can sit
+/// under the fold: bring it up before pressing it.
+Future<void> _tapScanWithPhone(WidgetTester tester) async {
+ final scan = find.byKey(const Key('login-scan-with-phone'));
+ await tester.ensureVisible(scan);
+ await tester.tap(scan);
+}
+
void main() {
testWidgets('offers "Scan with your phone", shows the QR, then asks whose account', (tester) async {
grid.AppTheme.brightness.value = Brightness.light;
@@ -95,8 +105,10 @@ void main() {
addTearDown(app.dispose);
await tester.pumpWidget(_host(app));
expect(find.byKey(const Key('login-scan-with-phone')), findsOneWidget);
+ // A way in of its own, set apart from the two accounts above it.
+ expect(find.byType(OrDivider), findsOneWidget);
- await tester.tap(find.byKey(const Key('login-scan-with-phone')));
+ await _tapScanWithPhone(tester);
await tester.pump();
expect(find.byKey(const Key('login-phone-qr')), findsOneWidget);
expect(find.textContaining('Sign in a computer'), findsOneWidget);
@@ -160,7 +172,7 @@ void main() {
..status = AppStatus.unauthenticated;
addTearDown(app.dispose);
await tester.pumpWidget(_host(app));
- await tester.tap(find.byKey(const Key('login-scan-with-phone')));
+ await _tapScanWithPhone(tester);
await tester.pump();
expect(find.text(_WaitingLogin.note), findsOneWidget);
// Its turn comes: the note goes with the wait.
@@ -219,7 +231,10 @@ class _SsoOnly implements SignInClient {
@override
Future<CliAuthStatus> checkStatus() async => const CliAuthStatus(loggedIn: false);
@override
- Future<void> login({required void Function(String url) onAuthorizeUrl}) async {}
+ Future<void> login({
+ required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {}
@override
void cancel() {}
@override
diff --git a/desktop/test/login_screen_test.dart b/desktop/test/login_screen_test.dart
index 678715156..8e2aec24c 100644
--- a/desktop/test/login_screen_test.dart
+++ b/desktop/test/login_screen_test.dart
@@ -1,9 +1,11 @@
+import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/screens/login_screen.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
@@ -39,14 +41,43 @@ Widget _host(
/// process, which a unit test must never do — it would block on a binary the
/// machine may not have.
class _FailingCliLogin extends CliLogin {
+ final providers = <SignInProvider?>[];
+
@override
Future<void> login({
required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
}) async {
+ providers.add(provider);
throw CliNotAvailableException('Could not run the harness CLI');
}
}
+/// A login that stays in flight until it is cancelled, recording which account
+/// each attempt named.
+class _WaitingCliLogin extends CliLogin {
+ final providers = <SignInProvider?>[];
+ Completer<void>? _pending;
+
+ @override
+ Future<void> login({
+ required void Function(String url) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) {
+ providers.add(provider);
+ return (_pending = Completer<void>()).future;
+ }
+
+ @override
+ void cancel() {
+ final pending = _pending;
+ _pending = null;
+ if (pending != null && !pending.isCompleted) {
+ pending.completeError(StateError('Sign-in was cancelled.'));
+ }
+ }
+}
+
AppNotifier _notifier(AppStatus status, {CliLogin? cliLogin}) {
grid.AppTheme.brightness.value = Brightness.light;
return AppNotifier(
@@ -79,7 +110,15 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Your agents, wherever they run'), findsOneWidget);
- expect(find.text('Sign in'), findsOneWidget);
+ // Two ways in, named — not one Sign in that left the choice to the browser.
+ expect(find.text('Continue with Google'), findsOneWidget);
+ expect(find.text('Continue with Apple'), findsOneWidget);
+ expect(find.text('Sign in'), findsNothing);
+ // One size, both of them.
+ expect(
+ tester.getSize(find.byKey(const Key('login-continue-google'))),
+ tester.getSize(find.byKey(const Key('login-continue-apple'))),
+ );
expect(find.byType(LoginFleetMap), findsOneWidget);
// The real mark, from the bundle — `AppIcons.cpu` used to stand here and
// appeared nowhere else in the app.
@@ -118,12 +157,62 @@ void main() {
expect(find.text('Waiting for your browser'), findsOneWidget);
expect(find.text('Cancel'), findsOneWidget);
// The idle label is gone, so the two states cannot both be on screen.
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
final button = tester.widget<FilledButton>(find.byType(FilledButton));
expect(button.onPressed, isNull, reason: 'in-flight, so not pressable');
});
+ testWidgets(
+ 'each button signs in with its own account, and says so while it waits',
+ (tester) async {
+ for (final provider in SignInProvider.values) {
+ final cli = _WaitingCliLogin();
+ final app = _notifier(AppStatus.unauthenticated, cliLogin: cli);
+ await tester.pumpWidget(_host(app));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ await tester.tap(find.text('Continue with ${provider.label}'));
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(cli.providers, [provider]);
+
+ // The pressed button is the one working; the other stays where it was,
+ // and neither can start a second sign-in.
+ final pressed = find.byKey(Key('login-continue-${provider.name}'));
+ expect(
+ find.descendant(of: pressed, matching: find.text('Signing in…')),
+ findsOneWidget,
+ );
+ final other = SignInProvider.values.firstWhere((p) => p != provider);
+ expect(find.text('Continue with ${other.label}'), findsOneWidget);
+ for (final button in tester.widgetList<FilledButton>(
+ find.byType(FilledButton),
+ )) {
+ expect(button.onPressed, isNull);
+ }
+
+ app.cancelLogin();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(find.text('Continue with ${provider.label}'), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ }
+ },
+ );
+
+ testWidgets('Try again goes back to the account that failed', (tester) async {
+ final cli = _FailingCliLogin();
+ final app = _notifier(AppStatus.unauthenticated, cliLogin: cli);
+ await app.login(SignInProvider.apple);
+ await tester.pumpWidget(_host(app));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ await tester.ensureVisible(find.text('Try again'));
+ await tester.tap(find.text('Try again'));
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(cli.providers, [SignInProvider.apple, SignInProvider.apple]);
+ });
+
testWidgets('a failure names itself and offers a way on', (tester) async {
final app = _notifier(
AppStatus.unauthenticated,
@@ -146,7 +235,7 @@ void main() {
final app = _notifier(AppStatus.unauthenticated);
await tester.pumpWidget(_host(app));
await tester.pumpAndSettle();
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
expect(find.byType(LoginFleetMap), findsOneWidget);
expect(tester.binding.hasScheduledFrame, isFalse);
await tester.pump(const Duration(milliseconds: 3200));
@@ -164,7 +253,7 @@ void main() {
// The example stays visible without depending on animation.
expect(find.byType(LoginFleetMap), findsOneWidget);
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
});
testWidgets('holds at the 880x560 minimum window without overflowing', (
@@ -179,10 +268,12 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(tester.takeException(), isNull);
- expect(find.text('Sign in'), findsOneWidget);
- expect(find.text('Sign in').hitTestable(), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
+ expect(find.text('Continue with Google').hitTestable(), findsOneWidget);
expect(
- tester.getRect(find.widgetWithText(FilledButton, 'Sign in')).bottom,
+ tester
+ .getRect(find.widgetWithText(FilledButton, 'Continue with Apple'))
+ .bottom,
lessThan(tester.view.physicalSize.height),
);
});
@@ -308,6 +399,6 @@ void main() {
// `panelBg`, not `windowBg` — in light the two ends of that pair are pure
// white and the card would have nothing to sit on.
expect(scaffold.backgroundColor, const Color(0xFF141414));
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
});
}
diff --git a/desktop/test/machine_list_outage_test.dart b/desktop/test/machine_list_outage_test.dart
index a9178ee5b..8c53f182f 100644
--- a/desktop/test/machine_list_outage_test.dart
+++ b/desktop/test/machine_list_outage_test.dart
@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/models.dart';
import 'package:harness/state/app_state.dart';
@@ -44,7 +45,10 @@ class _Cli extends CliLogin {
Future<CliAuthStatus> checkStatus() async =>
const CliAuthStatus(loggedIn: true);
@override
- Future<void> login({void Function(String url)? onAuthorizeUrl}) async {}
+ Future<void> login({
+ void Function(String url)? onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {}
@override
Future<void> logout() async {}
}
diff --git a/desktop/test/machine_list_push_test.dart b/desktop/test/machine_list_push_test.dart
index 10055092d..8d0d2b53d 100644
--- a/desktop/test/machine_list_push_test.dart
+++ b/desktop/test/machine_list_push_test.dart
@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/models.dart';
import 'package:harness/state/app_state.dart';
@@ -51,7 +52,10 @@ class _Cli extends CliLogin {
Future<CliAuthStatus> checkStatus() async =>
const CliAuthStatus(loggedIn: true);
@override
- Future<void> login({void Function(String url)? onAuthorizeUrl}) async {}
+ Future<void> login({
+ void Function(String url)? onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {}
@override
Future<void> logout() async {}
}
diff --git a/desktop/test/pane_machine_unknown_test.dart b/desktop/test/pane_machine_unknown_test.dart
index ac91f5b65..95463c0d1 100644
--- a/desktop/test/pane_machine_unknown_test.dart
+++ b/desktop/test/pane_machine_unknown_test.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:ui' as ui;
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -54,7 +55,10 @@ class _Cli extends CliLogin {
Future<CliAuthStatus> checkStatus() async =>
const CliAuthStatus(loggedIn: true);
@override
- Future<void> login({void Function(String url)? onAuthorizeUrl}) async {}
+ Future<void> login({
+ void Function(String url)? onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {}
@override
Future<void> logout() async {}
}
diff --git a/desktop/test/profile_startup_test.dart b/desktop/test/profile_startup_test.dart
index 45613407f..4d6c0d391 100644
--- a/desktop/test/profile_startup_test.dart
+++ b/desktop/test/profile_startup_test.dart
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/bootstrap/environment_provisioner.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/models.dart';
@@ -37,7 +38,10 @@ class _Cli extends CliLogin {
const CliAuthStatus(loggedIn: true);
@override
- Future<void> login({void Function(String url)? onAuthorizeUrl}) async {}
+ Future<void> login({
+ void Function(String url)? onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {}
@override
Future<void> logout() async {}
diff --git a/desktop/test/signin_recovery_test.dart b/desktop/test/signin_recovery_test.dart
index 5ecc8b6ad..afe66cbba 100644
--- a/desktop/test/signin_recovery_test.dart
+++ b/desktop/test/signin_recovery_test.dart
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/screens/login_screen.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
@@ -21,7 +22,10 @@ class _Cli extends CliLogin {
var cancellations = 0;
var statusChecks = 0;
@override
- Future<void> login({required void Function(String) onAuthorizeUrl}) {
+ Future<void> login({
+ required void Function(String) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) {
final attempt = _Attempt(onAuthorizeUrl);
attempts.add(attempt);
return attempt.done.future;
@@ -105,7 +109,7 @@ void main() {
expect(cli.cancellations, 1);
expect(app.pendingAuthorizeUrl, isNull);
expect(app.lastError, isNull);
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
expect(cli.cancellations, 1);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
@@ -197,7 +201,7 @@ void main() {
expect(app.signingIn, isFalse);
expect(app.status, AppStatus.unauthenticated);
expect(app.lastError, isNull);
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump(const Duration(milliseconds: 100));
expect(cli.attempts, hasLength(2));
diff --git a/desktop/test/signout_recovery_test.dart b/desktop/test/signout_recovery_test.dart
index df6079476..89d74068d 100644
--- a/desktop/test/signout_recovery_test.dart
+++ b/desktop/test/signout_recovery_test.dart
@@ -8,6 +8,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/screens/login_screen.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
@@ -29,7 +30,10 @@ class SignOutFixture extends CliLogin {
}
@override
- Future<void> login({required void Function(String) onAuthorizeUrl}) async {
+ Future<void> login({
+ required void Function(String) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {
logins++;
throw StateError('Fixture login stopped before any external work.');
}
@@ -211,7 +215,7 @@ void main() {
);
await tester.pump();
expect(find.text('Signing out…'), findsOneWidget);
- expect(find.text('Sign in'), findsNothing);
+ expect(find.text('Continue with Google'), findsNothing);
expect(find.text('Cancel'), findsNothing);
await capture('pending');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
@@ -242,7 +246,7 @@ void main() {
cli.attempts.last.complete();
await tester.pump();
await tester.pump();
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
await capture('ready');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
diff --git a/desktop/test/support/model_manager.dart b/desktop/test/support/model_manager.dart
index 1af121829..073da8f99 100644
--- a/desktop/test/support/model_manager.dart
+++ b/desktop/test/support/model_manager.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:harness/auth/auth_session.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/dsh_catalog.dart';
import 'package:harness/core/models.dart';
@@ -155,7 +156,7 @@ class ModelManagerTestApp extends AppNotifier {
bool loginLands = true;
@override
- Future<void> login() async {
+ Future<void> login([SignInProvider? provider]) async {
logins++;
signingIn = true;
notifyListeners();
diff --git a/desktop/test/viewer_auth_lifecycle_test.dart b/desktop/test/viewer_auth_lifecycle_test.dart
index 31488b4ad..2ba366c4d 100644
--- a/desktop/test/viewer_auth_lifecycle_test.dart
+++ b/desktop/test/viewer_auth_lifecycle_test.dart
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/local_key_value_store.dart';
import 'package:harness/viewer/direct_auth.dart';
@@ -34,18 +35,26 @@ class _Api extends DirectAuthApi {
final authorizations = <Completer<({String authorizeUrl, String tx})>>[];
final redirects = <String>[];
+ /// The client each refresh named.
+ final refreshClients = <String?>[];
+
@override
Future<IssuedTokens> refresh(
String refreshToken, {
required String autonomousEnv,
+ String? clientId,
}) {
final result = Completer<IssuedTokens>();
refreshes.add(result);
+ refreshClients.add(clientId);
return result.future;
}
@override
- Future<({String authorizeUrl, String tx})> authorizeNative(String uri) {
+ Future<({String authorizeUrl, String tx})> authorizeNative(
+ String uri, {
+ SignInProvider? provider,
+ }) {
redirects.add(uri);
final result = Completer<({String authorizeUrl, String tx})>();
authorizations.add(result);
@@ -196,6 +205,33 @@ void main() {
expect(api.refreshes, hasLength(1));
});
+ test('a session refreshes as the client it was issued to, and a later '
+ 'sign-in that names none inherits none', () async {
+ // auth-service refuses a refresh token presented under another client.
+ await auth.signIn(
+ const IssuedTokens(
+ token: 'old',
+ refreshToken: 'old-refresh',
+ clientId: 'harness-web',
+ ),
+ );
+ final first = auth.accessToken(force: true);
+ await _until(() => api.refreshes.isNotEmpty);
+ api.refreshes.single.complete(const IssuedTokens(token: 'renewed'));
+ expect(await first, 'renewed');
+ expect(api.refreshClients, ['harness-web']);
+ // The refresh's answer names no client: the session keeps the one it has.
+ expect(await session.ssoClientId(), 'harness-web');
+
+ // A backend from before the clients were split answers an exchange with none.
+ await auth.signIn(_old);
+ final second = auth.accessToken(force: true);
+ await _until(() => api.refreshes.length == 2);
+ api.refreshes.last.complete(const IssuedTokens(token: 'renewed-again'));
+ expect(await second, 'renewed-again');
+ expect(api.refreshClients, ['harness-web', null]);
+ });
+
for (final expires in [false, true]) {
test(
'${expires ? 'expired' : 'temporary'} refresh failure handles saved credentials truthfully',
diff --git a/desktop/test/web/browser_persistence_test.dart b/desktop/test/web/browser_persistence_test.dart
index 239513007..ff21fbd51 100644
--- a/desktop/test/web/browser_persistence_test.dart
+++ b/desktop/test/web/browser_persistence_test.dart
@@ -21,6 +21,7 @@ class _Api extends DirectAuthApi {
Future<IssuedTokens> refresh(
String refreshToken, {
required String autonomousEnv,
+ String? clientId,
}) async {
refreshCount++;
expect(refreshToken, 'fixture-refresh');
diff --git a/desktop/test/web/browser_workspace_test.dart b/desktop/test/web/browser_workspace_test.dart
index 44b5e7237..4c8baa5e7 100644
--- a/desktop/test/web/browser_workspace_test.dart
+++ b/desktop/test/web/browser_workspace_test.dart
@@ -416,13 +416,20 @@ void main() {
);
await tester.pump(const Duration(milliseconds: 100));
final download = tester.getRect(find.byType(WebDownloadButton));
- final signIn = tester.getRect(
- find.widgetWithText(FilledButton, 'Sign in'),
- );
- expect(download.bottom, lessThan(signIn.top));
+ // Both ways in, each a thumb's target, inside the phone's width.
+ for (final provider in ['Google', 'Apple']) {
+ final signIn = tester.getRect(
+ find.widgetWithText(FilledButton, 'Continue with $provider'),
+ );
+ expect(download.bottom, lessThan(signIn.top));
+ expect(signIn.right, lessThanOrEqualTo(390));
+ expect(signIn.height, greaterThanOrEqualTo(56));
+ expect(
+ find.text('Continue with $provider').hitTestable(),
+ findsOneWidget,
+ );
+ }
expect(download.right, lessThanOrEqualTo(390));
- expect(signIn.height, greaterThanOrEqualTo(56));
- expect(find.text('Sign in').hitTestable(), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
app.dispose();
diff --git a/desktop/test/workspace_account_lifecycle_test.dart b/desktop/test/workspace_account_lifecycle_test.dart
index 555e5baa4..948c71471 100644
--- a/desktop/test/workspace_account_lifecycle_test.dart
+++ b/desktop/test/workspace_account_lifecycle_test.dart
@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:harness/api/api_client.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/auth/cli_login.dart';
+import 'package:harness/auth/sign_in_provider.dart';
import 'package:harness/core/config.dart';
import 'package:harness/core/models.dart';
import 'package:harness/state/app_state.dart';
@@ -25,7 +26,10 @@ class WorkspaceAccountLogin extends CliLogin {
@override
Future<void> logout() async {}
@override
- Future<void> login({required void Function(String) onAuthorizeUrl}) async {
+ Future<void> login({
+ required void Function(String) onAuthorizeUrl,
+ SignInProvider? provider,
+ }) async {
logins++;
}
diff --git a/desktop/test/workspace_expiry_screen_test.dart b/desktop/test/workspace_expiry_screen_test.dart
index 2cf6175d7..c95131e86 100644
--- a/desktop/test/workspace_expiry_screen_test.dart
+++ b/desktop/test/workspace_expiry_screen_test.dart
@@ -47,14 +47,14 @@ void main() {
),
);
await tester.pump();
- expect(find.text('Sign in'), findsOneWidget);
+ expect(find.text('Continue with Google'), findsOneWidget);
expect(find.text('Could not sign in'), findsNothing);
expect(find.text('Try again'), findsNothing);
final notice = find.textContaining('You were signed out');
expect(notice, findsOneWidget);
expect(tester.getRect(notice).bottom, lessThanOrEqualTo(544));
expect(
- tester.getRect(find.text('Sign in')).top,
+ tester.getRect(find.text('Continue with Google')).top,
greaterThanOrEqualTo(16),
);
final directory = Platform.environment['HARNESS_AUTH_CAPTURE_DIR'];