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
use crate::AuthServiceClient;
use crate::error::{AuthServiceClientError, GenericErrorResponse};
use model::authentication::google_token::GoogleAccessToken;
impl AuthServiceClient {
/// Gets the Google access token for the given fusionauth user and linked email.
/// `email` corresponds to the `display_name` on the FusionAuth IdP link — i.e.
/// the linked Google account's email — which is the discriminator when one FA
/// user has multiple IdP links (multi-inbox).
#[tracing::instrument(skip(self))]
pub async fn get_google_access_token(
&self,
fusionauth_user_id: &str,
email: &str,
) -> Result<GoogleAccessToken, AuthServiceClientError> {
let res = self
.client
.get(format!("{}/internal/google_access_token", self.url))
.query(&[("fusionauth_user_id", fusionauth_user_id)])
.query(&[("email", email)])
.send()
.await
.map_err(|e| AuthServiceClientError::RequestBuildError {
details: e.to_string(),
})?;
match res.status() {
reqwest::StatusCode::OK => {
tracing::trace!("user access token retrieved");
let result = res.json::<GoogleAccessToken>().await.map_err(|e| {
AuthServiceClientError::Generic(GenericErrorResponse {
message: e.to_string(),
})
})?;
Ok(result)
}
reqwest::StatusCode::UNAUTHORIZED => Err(AuthServiceClientError::Unauthorized),
reqwest::StatusCode::FORBIDDEN => Err(AuthServiceClientError::Forbidden),
reqwest::StatusCode::NOT_FOUND => Err(AuthServiceClientError::NotFound),
reqwest::StatusCode::INTERNAL_SERVER_ERROR => {
let error_message = res.text().await.map_err(|e| {
AuthServiceClientError::Generic(GenericErrorResponse {
message: e.to_string(),
})
})?;
Err(AuthServiceClientError::InternalServerError {
details: error_message,
})
}
_ => {
let body = res.text().await.map_err(|e| {
AuthServiceClientError::Generic(GenericErrorResponse {
message: e.to_string(),
})
})?;
Err(AuthServiceClientError::Generic(GenericErrorResponse {
message: body,
}))
}
}
}
}