or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

app-management.mdauthentication.mdfirestore.mdfunctions.mdindex.mdmachine-learning.mdmessaging.mdproject-management.mdrealtime-database.mdremote-config.mdstorage.mdtenant-management.md

tenant-management.mddocs/

0

# Tenant Management

1

2

Multi-tenant authentication management using Google Cloud Identity Platform (GCIP), enabling isolated authentication environments within a single Firebase project. Each tenant provides independent user authentication while sharing the same Firebase project resources.

3

4

## Capabilities

5

6

### Tenant-Scoped Authentication

7

8

Get Auth client instances scoped to specific tenants for isolated authentication operations.

9

10

```python { .api }

11

def auth_for_tenant(tenant_id, app=None):

12

"""

13

Get an Auth Client instance scoped to the given tenant ID.

14

15

Args:

16

tenant_id: A tenant ID string

17

app: Firebase app instance (optional)

18

19

Returns:

20

auth.Client: An Auth client scoped to the specified tenant

21

22

Raises:

23

ValueError: If the tenant ID is None, empty or not a string

24

"""

25

```

26

27

### Tenant Retrieval

28

29

Get tenant information by tenant ID.

30

31

```python { .api }

32

def get_tenant(tenant_id, app=None):

33

"""

34

Get the tenant corresponding to the given tenant ID.

35

36

Args:

37

tenant_id: A tenant ID string

38

app: Firebase app instance (optional)

39

40

Returns:

41

Tenant: A tenant object

42

43

Raises:

44

ValueError: If the tenant ID is None, empty or not a string

45

TenantNotFoundError: If no tenant exists by the given ID

46

FirebaseError: If an error occurs while retrieving the tenant

47

"""

48

```

49

50

### Tenant Management

51

52

Create, update, and delete tenants with authentication configuration options.

53

54

```python { .api }

55

def create_tenant(display_name, allow_password_sign_up=None, enable_email_link_sign_in=None, app=None):

56

"""

57

Create a new tenant from the given options.

58

59

Args:

60

display_name: Display name for the new tenant (4-20 characters, letters/digits/hyphens)

61

allow_password_sign_up: Whether to enable email sign-in provider (optional)

62

enable_email_link_sign_in: Whether to enable email link sign-in (optional)

63

app: Firebase app instance (optional)

64

65

Returns:

66

Tenant: A tenant object

67

68

Raises:

69

ValueError: If any of the given arguments are invalid

70

FirebaseError: If an error occurs while creating the tenant

71

"""

72

73

def update_tenant(tenant_id, display_name=None, allow_password_sign_up=None, enable_email_link_sign_in=None, app=None):

74

"""

75

Update an existing tenant with the given options.

76

77

Args:

78

tenant_id: ID of the tenant to update

79

display_name: Updated display name for the tenant (optional)

80

allow_password_sign_up: Whether to enable email sign-in provider (optional)

81

enable_email_link_sign_in: Whether to enable email link sign-in (optional)

82

app: Firebase app instance (optional)

83

84

Returns:

85

Tenant: The updated tenant object

86

87

Raises:

88

ValueError: If any of the given arguments are invalid

89

TenantNotFoundError: If no tenant exists by the given ID

90

FirebaseError: If an error occurs while updating the tenant

91

"""

92

93

def delete_tenant(tenant_id, app=None):

94

"""

95

Delete the tenant corresponding to the given tenant ID.

96

97

Args:

98

tenant_id: A tenant ID string

99

app: Firebase app instance (optional)

100

101

Raises:

102

ValueError: If the tenant ID is None, empty or not a string

103

TenantNotFoundError: If no tenant exists by the given ID

104

FirebaseError: If an error occurs while deleting the tenant

105

"""

106

```

107

108

### Tenant Listing

109

110

List and paginate through all tenants in the Firebase project.

111

112

```python { .api }

113

def list_tenants(page_token=None, max_results=100, app=None):

114

"""

115

Retrieve a page of tenants from a Firebase project.

116

117

Args:

118

page_token: Token for paginating results (optional)

119

max_results: Maximum number of tenants to return (optional, max 100)

120

app: Firebase app instance (optional)

121

122

Returns:

123

ListTenantsPage: Page of tenant records with pagination info

124

125

Raises:

126

ValueError: If max_results or page_token are invalid

127

FirebaseError: If an error occurs while retrieving tenants

128

"""

129

```

130

131

## Types

132

133

```python { .api }

134

class Tenant:

135

"""Represents a tenant in a multi-tenant application."""

136

137

@property

138

def tenant_id(self):

139

"""The tenant ID."""

140

141

@property

142

def display_name(self):

143

"""The display name of the tenant."""

144

145

@property

146

def allow_password_sign_up(self):

147

"""Whether password sign-up is allowed."""

148

149

@property

150

def enable_email_link_sign_in(self):

151

"""Whether email link sign-in is enabled."""

152

153

class ListTenantsPage:

154

"""Page of tenant records with pagination."""

155

156

@property

157

def tenants(self):

158

"""List of Tenant instances in this page."""

159

160

@property

161

def next_page_token(self):

162

"""Token for the next page (empty string if no more pages)."""

163

164

@property

165

def has_next_page(self):

166

"""Whether there are more pages available."""

167

168

def get_next_page(self):

169

"""Get the next page of results."""

170

171

def iterate_all(self):

172

"""Iterator for all tenants starting from this page."""

173

174

class TenantNotFoundError(FirebaseError):

175

"""Error raised when a tenant is not found."""

176

177

class TenantIdMismatchError(FirebaseError):

178

"""Error raised when tenant ID doesn't match the expected value."""

179

```

180

181

## Usage Examples

182

183

### Basic Tenant Creation and Management

184

185

```python

186

import firebase_admin

187

from firebase_admin import credentials, tenant_mgt

188

189

# Initialize Firebase Admin SDK

190

cred = credentials.Certificate("path/to/serviceAccountKey.json")

191

firebase_admin.initialize_app(cred)

192

193

# Create a new tenant

194

tenant = tenant_mgt.create_tenant(

195

display_name="my-tenant-1",

196

allow_password_sign_up=True,

197

enable_email_link_sign_in=False

198

)

199

200

print(f"Created tenant: {tenant.tenant_id}")

201

print(f"Display name: {tenant.display_name}")

202

203

# Get tenant information

204

retrieved_tenant = tenant_mgt.get_tenant(tenant.tenant_id)

205

print(f"Retrieved tenant: {retrieved_tenant.display_name}")

206

207

# Update tenant

208

updated_tenant = tenant_mgt.update_tenant(

209

tenant.tenant_id,

210

display_name="updated-tenant-name",

211

enable_email_link_sign_in=True

212

)

213

214

# List all tenants

215

page = tenant_mgt.list_tenants()

216

for tenant in page.tenants:

217

print(f"Tenant: {tenant.tenant_id} - {tenant.display_name}")

218

```

219

220

### Tenant-Scoped Authentication

221

222

```python

223

from firebase_admin import tenant_mgt, auth

224

225

# Get Auth client scoped to a specific tenant

226

tenant_auth = tenant_mgt.auth_for_tenant("my-tenant-1")

227

228

# Use tenant-scoped auth operations

229

user = tenant_auth.create_user(

230

email="user@example.com",

231

password="password123"

232

)

233

234

# Create custom token for tenant user

235

custom_token = tenant_auth.create_custom_token(user.uid)

236

237

# All auth operations are scoped to the tenant

238

tenant_users = tenant_auth.list_users()

239

```