firebase_admin/auth/identity_toolkit/endpoints.rs
1//! URL builders for the Identity Toolkit REST API.
2//!
3//! # Implementation status
4//!
5//! Paths below match the Identity Toolkit v1 REST reference as of this
6//! writing, but must be re-confirmed against
7//! <https://cloud.google.com/identity-platform/docs/reference/rest> before
8//! the corresponding operations in [`crate::auth::users::operations`] are
9//! implemented — do not assume they are exact.
10
11const IDENTITY_TOOLKIT_BASE: &str = "https://identitytoolkit.googleapis.com/v1";
12
13/// Builds Identity Toolkit v1 REST endpoint URLs for a given project.
14pub struct IdentityToolkitEndpoints {
15 base: String,
16}
17
18impl IdentityToolkitEndpoints {
19 /// Endpoints pointed at the production Identity Toolkit API.
20 pub fn live() -> Self {
21 Self {
22 base: IDENTITY_TOOLKIT_BASE.to_string(),
23 }
24 }
25
26 /// Endpoints pointed at a local Firebase Auth Emulator instance.
27 ///
28 /// `host` is the emulator host and port, e.g. `localhost:9099`.
29 pub fn emulator(host: &str) -> Self {
30 Self {
31 base: format!("http://{host}/identitytoolkit.googleapis.com/v1"),
32 }
33 }
34
35 /// Endpoints pointed at an arbitrary base URL.
36 ///
37 /// Used by tests to point at a mock HTTP server; not exposed outside the
38 /// crate since real callers should use [`Self::live`] or
39 /// [`Self::emulator`].
40 #[cfg(test)]
41 pub(crate) fn custom(base: impl Into<String>) -> Self {
42 Self { base: base.into() }
43 }
44
45 /// `accounts:lookup` — fetch one or more users by uid, email, or phone number.
46 pub fn lookup(&self) -> String {
47 format!("{}/accounts:lookup", self.base)
48 }
49
50 /// `accounts:signUp` — create a new user (or, unauthenticated, sign one up).
51 pub fn sign_up(&self) -> String {
52 format!("{}/accounts:signUp", self.base)
53 }
54
55 /// `accounts:update` — update an existing user, including custom claims.
56 pub fn update(&self) -> String {
57 format!("{}/accounts:update", self.base)
58 }
59
60 /// `accounts:delete` — delete a user.
61 pub fn delete(&self) -> String {
62 format!("{}/accounts:delete", self.base)
63 }
64
65 /// `accounts:batchGet` — list users, paginated via `nextPageToken`.
66 pub fn batch_get(&self) -> String {
67 format!("{}/accounts:batchGet", self.base)
68 }
69
70 /// `accounts:createSessionCookie` — exchange an ID token for a session cookie.
71 pub fn create_session_cookie(&self) -> String {
72 format!("{}/accounts:createSessionCookie", self.base)
73 }
74}