Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(auth): expose linked GitHub identity in status response (#7109)
dev-rbceee72047a8a
diff --git a/apps/web/src/lib/service-clients/service-auth/generated/schemas/githubLinkStatusResponse.ts b/apps/web/src/lib/service-clients/service-auth/generated/schemas/githubLinkStatusResponse.tsindex 032271872b..b2c2096992 100644--- a/apps/web/src/lib/service-clients/service-auth/generated/schemas/githubLinkStatusResponse.ts+++ b/apps/web/src/lib/service-clients/service-auth/generated/schemas/githubLinkStatusResponse.ts@@ -6,6 +6,10 @@*/export interface GithubLinkStatusResponse {+ /** Stable ID of the authenticated user's linked GitHub account. */+ github_user_id: string;+ /** Login of the authenticated user's linked GitHub account. */+ github_username: string;/** Whether the user must reauthenticate their GitHub link. */reauthentication_required: boolean;}diff --git a/apps/web/src/lib/service-clients/service-auth/openapi.json b/apps/web/src/lib/service-clients/service-auth/openapi.jsonindex 2e198b17a5..88b7cb59fe 100644--- a/apps/web/src/lib/service-clients/service-auth/openapi.json+++ b/apps/web/src/lib/service-clients/service-auth/openapi.json@@ -5409,8 +5409,20 @@},"GithubLinkStatusResponse": {"type": "object",- "required": ["reauthentication_required"],+ "required": [+ "reauthentication_required",+ "github_username",+ "github_user_id"+ ],"properties": {+ "github_user_id": {+ "type": "string",+ "description": "Stable ID of the authenticated user's linked GitHub account."+ },+ "github_username": {+ "type": "string",+ "description": "Login of the authenticated user's linked GitHub account."+ },"reauthentication_required": {"type": "boolean","description": "Whether the user must reauthenticate their GitHub link."diff --git a/crates/github/src/domain/service/link.rs b/crates/github/src/domain/service/link.rsindex 96caad1fc9..2961dfdfc1 100644--- a/crates/github/src/domain/service/link.rs+++ b/crates/github/src/domain/service/link.rs@@ -141,7 +141,7 @@ impl<R: GithubRepo, U: GithubOauth, F: Auth, E: GithubPullRequestService> Githubself.repo.get_github_link_by_user_id(macro_user_id).await- .map_err(|e| GithubError::Internal(e.into()))+ .map_err(Self::link_lookup_error)}#[tracing::instrument(skip(self), err)]diff --git a/crates/github/src/domain/service/link_test.rs b/crates/github/src/domain/service/link_test.rsindex 55d6d86f43..f51e1ab4a9 100644--- a/crates/github/src/domain/service/link_test.rs+++ b/crates/github/src/domain/service/link_test.rs@@ -1,3 +1,4 @@+mod lookup;use std::sync::{Arc, Mutex};use chrono::Utc;diff --git a/crates/github/src/domain/service/link_test/lookup.rs b/crates/github/src/domain/service/link_test/lookup.rsnew file mode 100644index 0000000000..24681f4ac8--- /dev/null+++ b/crates/github/src/domain/service/link_test/lookup.rs@@ -0,0 +1,49 @@+use super::*;++#[tokio::test]+async fn get_user_link_returns_no_link_found_without_db_link() {+ let user_id = test_user_id();+ let service = service(+ StubGithubRepo::unlinked(),+ StubGithubOauth::new(false),+ StubAuth::new("valid-token"),+ );++ assert!(matches!(+ service.get_user_link(&user_id).await,+ Err(GithubError::NoLinkFound)+ ));+}++#[tokio::test]+async fn get_user_link_returns_no_link_found_after_concurrent_unlink() {+ let user_id = test_user_id();+ let repo = StubGithubRepo::linked(test_link(&user_id));+ let service = service(+ repo.clone(),+ StubGithubOauth::new(false),+ StubAuth::new("valid-token"),+ );+ service.check_user_link_token(&user_id).await.unwrap();+ repo.state.lock().unwrap().link_by_user_id = None;++ assert!(matches!(+ service.get_user_link(&user_id).await,+ Err(GithubError::NoLinkFound)+ ));+}++#[tokio::test]+async fn get_user_link_preserves_link_identity() {+ let user_id = test_user_id();+ let expected = test_link(&user_id);+ let service = service(+ StubGithubRepo::linked(expected.clone()),+ StubGithubOauth::new(false),+ StubAuth::new("valid-token"),+ );++ let actual = service.get_user_link(&user_id).await.unwrap();+ assert_eq!(actual.github_user_id, expected.github_user_id);+ assert_eq!(actual.github_username, expected.github_username);+}diff --git a/packages/sdk/generated/auth/types.gen.ts b/packages/sdk/generated/auth/types.gen.tsindex 0c1b8ca252..6650173cca 100644--- a/packages/sdk/generated/auth/types.gen.ts+++ b/packages/sdk/generated/auth/types.gen.ts@@ -554,6 +554,14 @@ export type GetUserInfo = {};export type GithubLinkStatusResponse = {+ /**+ * Stable ID of the authenticated user's linked GitHub account.+ */+ github_user_id: string;+ /**+ * Login of the authenticated user's linked GitHub account.+ */+ github_username: string;/*** Whether the user must reauthenticate their GitHub link.*/diff --git a/packages/sdk/specs/auth.json b/packages/sdk/specs/auth.jsonindex 2e198b17a5..88b7cb59fe 100644--- a/packages/sdk/specs/auth.json+++ b/packages/sdk/specs/auth.json@@ -5409,8 +5409,20 @@},"GithubLinkStatusResponse": {"type": "object",- "required": ["reauthentication_required"],+ "required": [+ "reauthentication_required",+ "github_username",+ "github_user_id"+ ],"properties": {+ "github_user_id": {+ "type": "string",+ "description": "Stable ID of the authenticated user's linked GitHub account."+ },+ "github_username": {+ "type": "string",+ "description": "Login of the authenticated user's linked GitHub account."+ },"reauthentication_required": {"type": "boolean","description": "Whether the user must reauthenticate their GitHub link."diff --git a/services/authentication_service/src/api/link/github.rs b/services/authentication_service/src/api/link/github.rsindex 2bff869505..fe6d13ef7b 100644--- a/services/authentication_service/src/api/link/github.rs+++ b/services/authentication_service/src/api/link/github.rs@@ -22,6 +22,10 @@ pub const REAUTHENTICATION_REQUIRED_MESSAGE: &str = "ReauthenticationRequired";pub struct GithubLinkStatusResponse {/// Whether the user must reauthenticate their GitHub link.pub reauthentication_required: bool,+ /// Login of the authenticated user's linked GitHub account.+ pub github_username: String,+ /// Stable ID of the authenticated user's linked GitHub account.+ pub github_user_id: String,}#[derive(serde::Deserialize, serde::Serialize, Debug, utoipa::ToSchema)]@@ -124,12 +128,16 @@ pub async fn check_github_link_status_handler(ip_context: ClientIp,authorization: MacroAuthorizationExtractor<AuthorizationService, UserOrInternal>,) -> Result<Json<GithubLinkStatusResponse>, GithubLinkStatusError> {+ let user_id = &authorization.authorization.user.macro_user_id;ctx.github_link_service- .check_user_link_token(&authorization.authorization.user.macro_user_id)+ .check_user_link_token(user_id).await?;+ let link = ctx.github_link_service.get_user_link(user_id).await?;Ok(Json(GithubLinkStatusResponse {reauthentication_required: false,+ github_username: link.github_username,+ github_user_id: link.github_user_id,}))}diff --git a/services/authentication_service/src/api/swagger.rs b/services/authentication_service/src/api/swagger.rsindex b5e810be31..c7ba4042f1 100644--- a/services/authentication_service/src/api/swagger.rs+++ b/services/authentication_service/src/api/swagger.rs@@ -344,6 +344,9 @@ mod tests {.get("GithubLinkStatusResponse").is_some());+ let fields = &openapi["components"]["schemas"]["GithubLinkStatusResponse"]["properties"];+ assert!(fields.get("github_username").is_some());+ assert!(fields.get("github_user_id").is_some());}#[test]