Skip to content

Add internal support for regionalized OIDC token exchange (BYO-CIAM) #14981

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

Open
wants to merge 1 commit into
base: auth-rgcip
Choose a base branch
from

Conversation

srushtisv
Copy link
Contributor

@srushtisv srushtisv commented Jun 14, 2025

Add request/response RPCs for regional OIDC token exchange feat(Auth)

Description

This PR introduces the internal request and response structures needed to support exchanging a third-party OIDC ID token for a Firebase ID token, specifically targeting the regionalized Google Cloud Identity Platform (R-GCIP) endpoints. This is a key part of the Bring Your Own CIAM (BYO-CIAM) feature.

Changes:

  • ExchangeTokenRequest.swift: New struct conforming to AuthRPCRequest.
    • Constructs the complete URL for the exchangeOidcToken endpoint, dynamically including the region and tenant ID from AuthRequestConfiguration.
    • Supports both staging and production regionalized hosts.
    • Includes idToken and idpConfigID as parameters.
    • Throws a fatal error if location, tenantId, or projectID are missing in the configuration, as these are critical for this regionalized flow.
  • ExchangeTokenResponse.swift: New struct conforming to AuthRPCResponse.
    • Parses the idToken (as firebaseToken) and expiresIn fields from the JSON response.
    • Calculates the token expirationDate.

This PR lays the internal groundwork for the new OIDC token exchange feature for regionalized tenants (R-GCIP).
To enable the Firebase Auth iOS SDK to communicate with the new regionalized identityplatform.googleapis.com service for exchanging tokens from external OIDC providers. This requires constructing specific URLs based on tenant and location, which these new structures handle.
These are internal additions to the networking layer and do not change the public API surface themselves. They will be used by higher-level functions (to be added/updated in subsequent PRs) that will expose the OIDC token exchange functionality to developers.

Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@srushtisv srushtisv self-assigned this Jun 14, 2025
@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

@srushtisv srushtisv requested a review from pashanka June 16, 2025 07:52
@srushtisv srushtisv marked this pull request as ready for review June 16, 2025 07:52
@srushtisv srushtisv requested a review from ncooke3 June 16, 2025 07:56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, but may be worth putting in a new directory to organize the regional-specific types.

- FirebaseAuth/Sources/Swift/Backend/RPC/ExchangeTokenRequest.swift
+ FirebaseAuth/Sources/Swift/Backend/RPC/Regionalization/ExchangeTokenRequest.swift

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srushtisv This is a good idea. This will help us segregate the flows clearly in the code.

let host = (location == "prod-global" || location == "global") ? baseHost :
"\(location)-\(baseHost)"

let locationPath = (location == "prod-global") ? "global" : location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Alternatively we can just keep the allowed value for location as global instead of prod-global

}
firebaseToken = token
/// Default to 1 hour (3600 seconds) if the field is missing.
expiresIn = dictionary["expiresIn"] as? TimeInterval ?? 3600
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check required here?This is an optional field in the backend. By adding this, we are setting an arbitrary value when backend is behaving unexpectedly which is not right.
Similar to how token is throwing error when idToken is missing, we should do the same for expiresIn

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srushtisv This is a good idea. This will help us segregate the flows clearly in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants