-
Notifications
You must be signed in to change notification settings - Fork 21
Add Outlook (Microsoft Graph) email provider support #3887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jbecke
wants to merge
5
commits into
main
Choose a base branch
from
claude/funny-bardeen-042qtp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b2b90e8
feat(email): add Outlook provider model + Microsoft Graph client
claude 92bac60
feat(auth): scaffold Outlook OAuth linking + token issuance
claude 48a7964
feat(email_service): wire Outlook client, webhook ingress + delta sync
claude 4916d2a
feat(app): add "Add Outlook inbox" connect flow
claude c02dad8
chore(infra): wire optional Outlook env vars into email-service stack
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { authServiceClient } from '@service-auth/client'; | ||
| import { useMutation } from '@tanstack/solid-query'; | ||
|
|
||
| /** | ||
| * Mutation that asks auth-service for the Microsoft OAuth authorization URL for | ||
| * adding an Outlook inbox to the already-authenticated user. Callers consume the | ||
| * `authorization_url` and navigate the browser to it. Mirrors | ||
| * {@link useInitGmailLink}. | ||
| */ | ||
| export function useInitOutlookLink() { | ||
| return useMutation(() => ({ | ||
| mutationFn: async (originalUrl: string) => { | ||
| return authServiceClient.initOutlookLink(originalUrl); | ||
| }, | ||
| })); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
rust/cloud-storage/authentication_service/src/api/internal/microsoft_access_token.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| use axum::{ | ||
| Json, | ||
| extract::{self, State}, | ||
| http::StatusCode, | ||
| response::{IntoResponse, Response}, | ||
| }; | ||
| use fusionauth::FusionAuthClient; | ||
| use fusionauth::error::FusionAuthClientError; | ||
| use macro_middleware::auth::internal_access::ValidInternalKey; | ||
| use model::authentication::microsoft_token::MicrosoftAccessToken; | ||
| use model::response::ErrorResponse; | ||
| use std::sync::Arc; | ||
|
|
||
| /// FusionAuth identity-provider name for the Microsoft (Outlook) IdP. Mirrors | ||
| /// the `google_gmail` name used for Gmail. | ||
| pub(crate) const OUTLOOK_IDENTITY_PROVIDER_NAME: &str = "microsoft_outlook"; | ||
|
|
||
| #[derive(serde::Deserialize, Debug)] | ||
| pub struct MicrosoftAccessTokenParams { | ||
| fusionauth_user_id: String, | ||
| /// The linked Microsoft account's email — what FusionAuth stores as | ||
| /// `display_name` on the IdP link. Discriminates one Microsoft account from | ||
| /// another when the FA user has multiple Microsoft IdP links. | ||
| email: String, | ||
| } | ||
|
|
||
| /// Gets a Microsoft (Outlook) access token for the linked account. Mirrors the | ||
| /// Gmail `google_access_token` handler. | ||
| #[tracing::instrument(skip(auth_client, _internal_access))] | ||
| pub async fn handler( | ||
| State(auth_client): State<Arc<FusionAuthClient>>, | ||
| _internal_access: ValidInternalKey, | ||
| extract::Query(params): extract::Query<MicrosoftAccessTokenParams>, | ||
| ) -> Result<Response, Response> { | ||
| get_access_token(auth_client, ¶ms, OUTLOOK_IDENTITY_PROVIDER_NAME).await | ||
| } | ||
|
|
||
| /// Fetches an access token for a user from the Microsoft identity provider by | ||
| /// looking up their IdP link and refreshing the stored refresh token. | ||
| #[tracing::instrument(skip(auth_client))] | ||
| async fn get_access_token( | ||
| auth_client: Arc<FusionAuthClient>, | ||
| params: &MicrosoftAccessTokenParams, | ||
| identity_provider_name: &str, | ||
| ) -> Result<Response, Response> { | ||
| let fusionauth_user_id = params.fusionauth_user_id.as_str(); | ||
| let email = params.email.as_str(); | ||
|
|
||
| // get identity provider id | ||
| let idp_id = auth_client | ||
| .get_identity_provider_id_by_name(identity_provider_name) | ||
| .await | ||
| .map_err(|e| { | ||
| tracing::error!(error=?e, "unable to find idp id for {}", identity_provider_name); | ||
| ( | ||
| StatusCode::INTERNAL_SERVER_ERROR, | ||
| Json(ErrorResponse { | ||
| message: "unable to find idp".into(), | ||
| }), | ||
| ) | ||
| .into_response() | ||
| })?; | ||
|
|
||
| // get refresh token via link | ||
| let links = auth_client | ||
| .get_links(fusionauth_user_id, Some(idp_id.clone())) | ||
| .await | ||
| .map_err(|e| { | ||
| tracing::error!(error=?e, "error fetching links for userid {} and idp id {}", fusionauth_user_id, idp_id.as_str()); | ||
| ( | ||
| StatusCode::INTERNAL_SERVER_ERROR, | ||
| Json(ErrorResponse { | ||
| message: "unable to fetch links".into(), | ||
| }), | ||
| ) | ||
| .into_response() | ||
| })?; | ||
|
|
||
| // a fusionauth user can have multiple links to the same identity provider with different email | ||
| // addresses, but can only have one link with a given email | ||
| let link = links | ||
| .into_iter() | ||
| .find(|l| l.display_name.as_str() == email) | ||
| .ok_or_else(|| { | ||
| tracing::error!( | ||
| "link not found for user id {} and idp id {}", | ||
| fusionauth_user_id, | ||
| idp_id.as_str() | ||
| ); | ||
| ( | ||
| StatusCode::NOT_FOUND, | ||
| Json(ErrorResponse { | ||
| message: format!("No {} link found for this user", identity_provider_name) | ||
| .into(), | ||
| }), | ||
| ) | ||
| .into_response() | ||
| })?; | ||
|
|
||
| // get access token using refresh token | ||
| let token_response = auth_client | ||
| .refresh_microsoft_token(link.token.as_str()) | ||
| .await | ||
| .map_err(|e| { | ||
| tracing::error!(error=?e, "error fetching microsoft access token for userid {}", fusionauth_user_id); | ||
| let status_code = match &e { | ||
| FusionAuthClientError::InvalidGrant => StatusCode::FORBIDDEN, | ||
| _ => StatusCode::INTERNAL_SERVER_ERROR, | ||
| }; | ||
| let message = format!("unable to fetch {} access token", identity_provider_name); | ||
| (status_code, Json(ErrorResponse { message: message.into() })).into_response() | ||
| })?; | ||
|
|
||
| Ok(( | ||
| StatusCode::OK, | ||
| Json(MicrosoftAccessToken { | ||
| access_token: token_response.access_token, | ||
| }), | ||
| ) | ||
| .into_response()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stop tracing raw query params with user identifiers/email.
Current span instrumentation captures
params(andDebug-formats it), which can leak PII in traces/log pipelines.Suggested fix
Also applies to: 29-45
🤖 Prompt for AI Agents