Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ios): auth failures (#5530)

Peter Chinman091f4219e05f
diff --git a/apps/web/package.json b/apps/web/package.json
index 12a78f0346..41d1d493ca 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -49,11 +49,11 @@
"@fontsource-variable/inter": "^5.2.8",
"@fontsource-variable/playfair-display": "^5.2.8",
"@fontsource-variable/roboto-mono": "^5.2.8",
+ "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#6ddd6600e20436388f169e936b610fe93944b7b0",
"@fullcalendar/core": "^6.1.21",
"@fullcalendar/daygrid": "^6.1.21",
"@fullcalendar/interaction": "^6.1.21",
"@fullcalendar/timegrid": "^6.1.21",
- "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef",
"@kobalte/core": "^0.13.11",
"@leeoniya/ufuzzy": "^1.0.19",
"@lexical/history": "0.45.0",
diff --git a/apps/web/src/features/auth/Login.tsx b/apps/web/src/features/auth/Login.tsx
index 650f8fbe8a..8638b3a570 100644
--- a/apps/web/src/features/auth/Login.tsx
+++ b/apps/web/src/features/auth/Login.tsx
@@ -4,6 +4,7 @@ import { useOnboardingV4Flag } from '@app/features/setup/flow/useOnboardingV4Fla
import { useAnalytics } from '@app/lib/analytics/analytics-context';
import { GOOGLE_GMAIL_IDP } from '@core/auth/email';
import { LoadingBlock } from '@core/component/LoadingBlock';
+import { toast } from '@core/component/Toast/Toast';
import { useEmailLinks } from '@core/email-link';
import { isMobile } from '@core/mobile/isMobile';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
@@ -504,6 +505,9 @@ export function Login(props: { signupMode?: boolean }) {
}
}
);
+ } else {
+ console.error('Failed to redeem session code', res.error);
+ toast.failure('Sign-in failed. Please try again.');
}
});
}
diff --git a/apps/web/src/features/auth/useSsoLogin.ts b/apps/web/src/features/auth/useSsoLogin.ts
index d5b5e00229..ebb34d8189 100644
--- a/apps/web/src/features/auth/useSsoLogin.ts
+++ b/apps/web/src/features/auth/useSsoLogin.ts
@@ -1,5 +1,6 @@
import type { AnalyticsProvider } from '@app/lib/analytics';
import { useAnalytics } from '@app/lib/analytics/analytics-context';
+import { toast } from '@core/component/Toast/Toast';
import { SERVER_HOSTS } from '@core/constant/servers';
import { useEmailLinks } from '@core/email-link';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
@@ -56,7 +57,11 @@ export function useSsoLogin(opts?: { signupMode?: boolean }) {
});
if (!result.success || !result.token) {
- console.error('Authentication failed:', result.error);
+ // A canceled sheet is a deliberate user action, not a failure.
+ if (result.error !== 'User canceled login') {
+ console.error('Authentication failed:', result.error);
+ toast.failure('Sign-in failed. Please try again.');
+ }
return;
}
@@ -76,6 +81,9 @@ export function useSsoLogin(opts?: { signupMode?: boolean }) {
}
}
);
+ } else {
+ console.error('Failed to redeem session code', res.error);
+ toast.failure('Sign-in failed. Please try again.');
}
analytics.track(analyticsEvent, { method: idp_name }, analyticsProviders);
diff --git a/apps/web/src/lib/core/auth/sso.ts b/apps/web/src/lib/core/auth/sso.ts
deleted file mode 100644
index d61d9ee9e1..0000000000
--- a/apps/web/src/lib/core/auth/sso.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-import { SERVER_HOSTS } from '@core/constant/servers';
-import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
-import { unsetTokenPromise } from '@core/util/fetchWithToken';
-
-import { getNativeMobilePlatform } from '@core/util/platform';
-import { invalidateAllAfterLogin } from '@queries/auth/user-info';
-import { authServiceClient } from '@service-auth/client';
-import { invoke } from '@tauri-apps/api/core';
-import { GOOGLE_GMAIL_IDP } from './email';
-
-type StartSsoLoginParams = {
- idpName?: string;
- /** Where to redirect after auth on web. Ignored on native mobile. */
- returnPath?: string;
- /** Pre-fill the email field on the OAuth provider's login screen. */
- loginHint?: string;
-};
-
-/**
- * Starts an SSO login flow.
- * - Native iOS: performs auth inline via Tauri plugin, returns true on success.
- * - Web: redirects to the SSO URL (the returned promise never resolves).
- */
-export async function startSsoLogin(
- params: StartSsoLoginParams = {}
-): Promise<boolean> {
- const idpName = params.idpName ?? GOOGLE_GMAIL_IDP;
- const authUrl = new URL(`${SERVER_HOSTS['auth-service']}/login/sso`);
- authUrl.searchParams.set('idp_name', idpName);
-
- const referralCode = new URL(window.location.href).searchParams.get(
- 'referral_code'
- );
- if (referralCode) authUrl.searchParams.set('referral_code', referralCode);
- if (params.loginHint)
- authUrl.searchParams.set('login_hint', params.loginHint);
-
- if (isNativeMobilePlatform()) {
- authUrl.searchParams.set('is_mobile', 'true');
- }
-
- if (getNativeMobilePlatform() === 'ios') {
- authUrl.searchParams.set('original_url', 'macro://login');
-
- const result = await invoke<{
- success: boolean;
- token?: string;
- error?: string;
- }>('plugin:auth|authenticate', {
- payload: {
- authUrl: authUrl.toString(),
- callbackScheme: 'macro',
- ephemeralSession: true,
- },
- });
-
- if (!result.success || !result.token) {
- console.error('Authentication failed:', result.error);
- return false;
- }
-
- unsetTokenPromise();
- const res = await authServiceClient.sessionLogin({
- session_code: result.token,
- });
-
- if (res.isOk()) {
- await invalidateAllAfterLogin();
- return true;
- }
-
- return false;
- }
-
- // Web: redirect to SSO — page navigates away, promise never resolves.
- if (params.returnPath) {
- authUrl.searchParams.set(
- 'original_url',
- `${window.location.origin}${params.returnPath}`
- );
- } else {
- authUrl.searchParams.set('original_url', window.location.href);
- }
- window.location.href = authUrl.toString();
- return new Promise(() => {});
-}
diff --git a/apps/web/src/lib/service-clients/service-auth/client.ts b/apps/web/src/lib/service-clients/service-auth/client.ts
index 6b974b0891..2f0d1a5bdd 100644
--- a/apps/web/src/lib/service-clients/service-auth/client.ts
+++ b/apps/web/src/lib/service-clients/service-auth/client.ts
@@ -193,8 +193,11 @@ export const authServiceClient = {
}));
},
async sessionLogin(args: { session_code: string }) {
+ // The session code stays valid server-side for 5 minutes and is
+ // replayable, so retrying transient failures is safe.
const result = await authApiFetch<UserTokensResponse>(
- `/session/login/${args.session_code}`
+ `/session/login/${args.session_code}`,
+ { retry: { maxTries: 3, delay: 'exponential' } }
);
if (result.isOk()) {
setAccessTokenData({
diff --git a/apps/web/tauri/Cargo.lock b/apps/web/tauri/Cargo.lock
index fd50a60743..ce10adf788 100644
--- a/apps/web/tauri/Cargo.lock
+++ b/apps/web/tauri/Cargo.lock
@@ -2482,7 +2482,7 @@ dependencies = [
"js-sys",
"log",
"wasm-bindgen",
- "windows-core 0.57.0",
+ "windows-core 0.58.0",
]
[[package]]
@@ -5803,7 +5803,7 @@ dependencies = [
[[package]]
name = "tauri-plugin-auth"
version = "0.1.0"
-source = "git+https://github.com/macro-inc/tauri-plugins?rev=26537c8a46bb8424f9cf4021d08aa76aa7cd66ef#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef"
+source = "git+https://github.com/macro-inc/tauri-plugins?rev=6ddd6600e20436388f169e936b610fe93944b7b0#6ddd6600e20436388f169e936b610fe93944b7b0"
dependencies = [
"serde",
"tauri",
@@ -5974,7 +5974,7 @@ dependencies = [
[[package]]
name = "tauri-plugin-notifications"
version = "0.1.0"
-source = "git+https://github.com/macro-inc/tauri-plugins?rev=26537c8a46bb8424f9cf4021d08aa76aa7cd66ef#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef"
+source = "git+https://github.com/macro-inc/tauri-plugins?rev=6ddd6600e20436388f169e936b610fe93944b7b0#6ddd6600e20436388f169e936b610fe93944b7b0"
dependencies = [
"serde",
"tauri",
diff --git a/apps/web/tauri/src-tauri/Cargo.toml b/apps/web/tauri/src-tauri/Cargo.toml
index 32f4111f0a..677c240908 100644
--- a/apps/web/tauri/src-tauri/Cargo.toml
+++ b/apps/web/tauri/src-tauri/Cargo.toml
@@ -65,7 +65,7 @@ graphql_cache_plugin = { path = "../graphql_cache_plugin" }
macro_bundle_updater_plugin = { path = "../macro_bundle_updater_plugin" }
navigation_plugin = { path = "../navigation_plugin" }
tauri-plugin-device-info = "1.0.1"
-tauri-plugin-notifications = { git = "https://github.com/macro-inc/tauri-plugins", rev = "26537c8a46bb8424f9cf4021d08aa76aa7cd66ef" }
+tauri-plugin-notifications = { git = "https://github.com/macro-inc/tauri-plugins", rev = "6ddd6600e20436388f169e936b610fe93944b7b0" }
tauri-plugin-os = "2"
tauri-plugin-virtual-keyboard = { git = "https://github.com/voxelbee/tauri-plugin-virtual-keyboard", branch = "main" }
@@ -74,7 +74,7 @@ tauri-plugin-virtual-keyboard = { git = "https://github.com/voxelbee/tauri-plugi
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]
-tauri-plugin-auth = { git = "https://github.com/macro-inc/tauri-plugins", rev = "26537c8a46bb8424f9cf4021d08aa76aa7cd66ef" }
+tauri-plugin-auth = { git = "https://github.com/macro-inc/tauri-plugins", rev = "6ddd6600e20436388f169e936b610fe93944b7b0" }
tauri-plugin-haptics = "2"
[target.'cfg(target_os = "ios")'.dependencies]
diff --git a/bun.lock b/bun.lock
index 809ba91d74..07ca0f17cf 100644
--- a/bun.lock
+++ b/bun.lock
@@ -29,7 +29,7 @@
"@fullcalendar/daygrid": "^6.1.21",
"@fullcalendar/interaction": "^6.1.21",
"@fullcalendar/timegrid": "^6.1.21",
- "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#26537c8a46bb8424f9cf4021d08aa76aa7cd66ef",
+ "@inkibra/tauri-plugins": "git+https://github.com/macro-inc/tauri-plugins.git#6ddd6600e20436388f169e936b610fe93944b7b0",
"@kobalte/core": "^0.13.11",
"@leeoniya/ufuzzy": "^1.0.19",
"@lexical/history": "0.45.0",
@@ -943,7 +943,7 @@
"@img/sharp-win32-x64": ["@img/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw=="],
- "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8", "sha512-6p5xQAkS6Uw6J8Uh0vlj6MjKZXWps5E1Gu0hciBFq1E2BfPBZAgdeeafKnR3diNb4SXWK0JML49nAr+o5PhwKw=="],
+ "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#6ddd660", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-6ddd660"],
"@inquirer/ansi": ["@inquirer/[email protected]", "", {}, "sha512-3eTuUO1vH2cZm2ZKHeQxnOqlTi9EfZDGgIe3BL3I4u+rJHocr9Fz86M4fjYABPvFnQG/gGK551HqDiIcETwU6Q=="],
@@ -2721,7 +2721,7 @@
"pathval": ["[email protected]", "", {}, "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ=="],
- "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6", "sha512-HDFaPbCxLG2GHpf1smUG97nku5aPGBGaCcIbK05dGdp07TBLUlDcXsM4WcE82mO5W4RBPIBVYobX5N/6M6NFrA=="],
+ "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6"],
"performance-now": ["[email protected]", "", {}, "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="],
diff --git a/nix-support/node_modules-hashes.json b/nix-support/node_modules-hashes.json
index e9e1101d80..a99d455793 100644
--- a/nix-support/node_modules-hashes.json
+++ b/nix-support/node_modules-hashes.json
@@ -1,6 +1,6 @@
{
"nodeModules": {
- "aarch64-darwin": "sha256-gq79YeOfdlBbZJ0/WdoVtqpQq54SJFxtFaSQnkbgJls=",
- "x86_64-linux": "sha256-XEgtdhzfBGs24hD/30mFUDcwvWZe8q1vlOYyyfIQ3Y4="
+ "aarch64-darwin": "sha256-9x1b9zuc0ivnL1QuHPWOSftMsCcfx6L4qYHlMb47ie4=",
+ "x86_64-linux": "sha256-rbBTSaprnzGuUZ5iZqtbMRj0cWyfJhL51PXz8NvumAI="
}
}
diff --git a/services/authentication_service/src/api/login/sso.rs b/services/authentication_service/src/api/login/sso.rs
index fbc1171b0e..fa805b6de2 100644
--- a/services/authentication_service/src/api/login/sso.rs
+++ b/services/authentication_service/src/api/login/sso.rs
@@ -68,7 +68,9 @@ fn is_allowed_original_url(url: &Url) -> bool {
(status = 500, body=ErrorResponse),
)
)]
-#[tracing::instrument(skip(ctx))]
+// `query` is skipped: original_url is client-controlled (query/fragment may
+// carry tokens) and login_hint is a user email — neither belongs in span fields.
+#[tracing::instrument(skip(ctx, query), fields(idp_name = ?query.idp_name, idp_id = ?query.idp_id, is_mobile = query.is_mobile))]
pub async fn handler(
State(ctx): State<ApiContext>,
query: Query<LoginQueryParams>,
@@ -83,11 +85,21 @@ pub async fn handler(
}) = query;
let original_url = original_url.map(|url| url.0);
- if original_url
+ if let Some(url) = original_url
.as_ref()
- .is_some_and(|url| !is_allowed_original_url(url))
+ .filter(|url| !is_allowed_original_url(url))
{
- tracing::error!("original_url is not allowed");
+ // Log scheme://host/path only — the query and fragment are
+ // client-controlled and may carry tokens or PII. The path is kept
+ // because it distinguishes e.g. macro://login from macro:///login.
+ let mut redacted_url = url.clone();
+ redacted_url.set_query(None);
+ redacted_url.set_fragment(None);
+ tracing::error!(
+ auth_handoff_failure = "original_url_rejected",
+ original_url = %redacted_url,
+ "original_url is not allowed"
+ );
return Err((
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
diff --git a/services/authentication_service/src/api/oauth/oauth_redirect.rs b/services/authentication_service/src/api/oauth/oauth_redirect.rs
index 2c1ea33cff..4a541c9c29 100644
--- a/services/authentication_service/src/api/oauth/oauth_redirect.rs
+++ b/services/authentication_service/src/api/oauth/oauth_redirect.rs
@@ -63,6 +63,7 @@ pub async fn handler(
Some(c) => c,
None => {
tracing::warn!(
+ auth_handoff_failure = "missing_code",
error = ?params.error,
error_reason = ?params.error_reason,
error_description = ?params.error_description,
@@ -91,7 +92,11 @@ pub async fn handler(
{
Ok(tokens) => tokens,
Err(e) => {
- tracing::error!(error=?e, "unable to complete authorization code grant");
+ tracing::error!(
+ auth_handoff_failure = "code_grant_failed",
+ error=?e,
+ "unable to complete authorization code grant"
+ );
return Err(StatusCode::INTERNAL_SERVER_ERROR.into_response());
}
};
@@ -100,6 +105,13 @@ pub async fn handler(
ctx.macro_cache_client
.set_mobile_login_session(code.0.as_str(), &refresh_token)
.await
+ .inspect_err(|e| {
+ tracing::error!(
+ auth_handoff_failure = "session_code_store_failed",
+ error=?e,
+ "unable to store mobile session code"
+ );
+ })
.map_err(InnerErr::MacroCacheErr)
};
@@ -107,6 +119,13 @@ pub async fn handler(
Some(
state
.decode()
+ .inspect_err(|e| {
+ tracing::error!(
+ auth_handoff_failure = "state_decode_failed",
+ error=?e,
+ "unable to decode oauth state"
+ );
+ })
.map_err(|e| InnerErr::Serde(e).into_response())?,
)
} else {
@@ -124,9 +143,14 @@ pub async fn handler(
if let Some(state) = state.as_ref()
&& let Some(referral_code) = state.referral_code.as_ref()
{
- let user_id = decoded_user_id
- .as_ref()
- .map_err(|_| InnerErr::InvalidJwtError.into_response())?;
+ let user_id = decoded_user_id.as_ref().map_err(|e| {
+ tracing::error!(
+ auth_handoff_failure = "referral_jwt_decode_failed",
+ error=?e,
+ "unable to decode access token while tracking referral"
+ );
+ InnerErr::InvalidJwtError.into_response()
+ })?;
let _ = ctx
.referral_service
@@ -211,6 +235,13 @@ async fn get_redirect_url(
write_db: impl AsyncFnOnce(&SessionCode) -> Result<(), InnerErr>,
) -> Result<Url, InnerErr> {
let Some(state) = state else {
+ // A mobile login cannot complete from here: without state there is no
+ // is_mobile flag, so no session code is minted and the app's
+ // macro:// callback never fires.
+ tracing::warn!(
+ auth_handoff_failure = "state_missing",
+ "oauth redirect received without state; redirecting to default app url"
+ );
return Ok(default_redirect_url());
};
diff --git a/services/authentication_service/src/api/session/session_login.rs b/services/authentication_service/src/api/session/session_login.rs
index 63dab09ed0..bde057d792 100644
--- a/services/authentication_service/src/api/session/session_login.rs
+++ b/services/authentication_service/src/api/session/session_login.rs
@@ -46,7 +46,11 @@ pub async fn handler(
.get_mobile_login_session(&session_code)
.await
.map_err(|e| {
- tracing::error!(error=?e, "failed to get mobile login session");
+ tracing::error!(
+ auth_handoff_failure = "session_code_lookup_failed",
+ error=?e,
+ "failed to get mobile login session"
+ );
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(ErrorResponse {
@@ -57,6 +61,10 @@ pub async fn handler(
})?;
if refresh_token.is_none() {
+ tracing::warn!(
+ auth_handoff_failure = "session_code_invalid",
+ "mobile session code not found or expired"
+ );
return Err((
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
@@ -72,7 +80,11 @@ pub async fn handler(
.refresh_token("", &refresh_token)
.await
.map_err(|e| {
- tracing::error!(error=?e, "unable to refresh token");
+ tracing::error!(
+ auth_handoff_failure = "session_refresh_failed",
+ error=?e,
+ "unable to refresh token"
+ );
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(ErrorResponse {