Skip to content

Commit 8e08c5e

Browse files
authored
chore(auth): Exposed admin.auth namespace (#1053)
* chore(auth): Exposed admin.auth namespace * fix(auth): Fixing unit tests for SAMLConfig * fix(auth): Removing more auth. prefixed direct references * fix(auth): Using CreateTenantRequest explicitly where appropriate
1 parent b12f4e2 commit 8e08c5e

21 files changed

+2280
-480
lines changed

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ gulp.task('compile', function() {
8383

8484
const configuration = [
8585
'lib/**/*.js',
86+
'lib/auth/index.d.ts',
8687
'lib/credential/index.d.ts',
8788
'lib/firebase-namespace-api.d.ts',
8889
'lib/database/index.d.ts',

src/auth/action-code-settings-builder.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,9 @@
1616

1717
import * as validator from '../utils/validator';
1818
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
19+
import { auth } from './index';
1920

20-
/** Defines the ActionCodeSettings interface. */
21-
export interface ActionCodeSettings {
22-
url: string;
23-
handleCodeInApp?: boolean;
24-
iOS?: {
25-
bundleId: string;
26-
};
27-
android?: {
28-
packageName: string;
29-
installApp?: boolean;
30-
minimumVersion?: string;
31-
};
32-
dynamicLinkDomain?: string;
33-
}
21+
import ActionCodeSettings = auth.ActionCodeSettings;
3422

3523
/** Defines the email action code server request. */
3624
interface EmailActionCodeRequest {

src/auth/auth-api-request.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@ import * as validator from '../utils/validator';
1818

1919
import { deepCopy, deepExtend } from '../utils/deep-copy';
2020
import {
21-
UserIdentifier, isUidIdentifier, isEmailIdentifier, isPhoneIdentifier,
22-
isProviderIdentifier, UidIdentifier, EmailIdentifier, PhoneIdentifier,
23-
ProviderIdentifier,
21+
isUidIdentifier, isEmailIdentifier, isPhoneIdentifier, isProviderIdentifier
2422
} from './identifier';
2523
import { FirebaseApp } from '../firebase-app';
2624
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
2725
import {
2826
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, HttpError,
2927
} from '../utils/api-request';
30-
import { CreateRequest, UpdateRequest } from './user-record';
3128
import {
32-
UserImportBuilder, UserImportOptions, UserImportRecord,
33-
UserImportResult, AuthFactorInfo, convertMultiFactorInfoToServerFormat,
29+
UserImportBuilder, AuthFactorInfo, convertMultiFactorInfoToServerFormat,
3430
} from './user-import-builder';
3531
import * as utils from '../utils/index';
36-
import { ActionCodeSettings, ActionCodeSettingsBuilder } from './action-code-settings-builder';
32+
import { ActionCodeSettingsBuilder } from './action-code-settings-builder';
3733
import {
3834
SAMLConfig, OIDCConfig, OIDCConfigServerResponse, SAMLConfigServerResponse,
39-
OIDCConfigServerRequest, SAMLConfigServerRequest, AuthProviderConfig,
40-
OIDCUpdateAuthProviderRequest, SAMLUpdateAuthProviderRequest,
35+
OIDCConfigServerRequest, SAMLConfigServerRequest,
4136
} from './auth-config';
42-
import { Tenant, TenantOptions, TenantServerResponse } from './tenant';
43-
37+
import { Tenant, TenantServerResponse } from './tenant';
38+
import { auth } from './index';
39+
40+
import CreateRequest = auth.CreateRequest;
41+
import UpdateRequest = auth.UpdateRequest;
42+
import UserIdentifier = auth.UserIdentifier;
43+
import UidIdentifier = auth.UidIdentifier;
44+
import EmailIdentifier = auth.EmailIdentifier;
45+
import PhoneIdentifier = auth.PhoneIdentifier;
46+
import ProviderIdentifier = auth.ProviderIdentifier;
47+
import UserImportOptions = auth.UserImportOptions;
48+
import UserImportRecord = auth.UserImportRecord;
49+
import UserImportResult = auth.UserImportResult;
50+
import ActionCodeSettings = auth.ActionCodeSettings;
51+
import OIDCAuthProviderConfig = auth.OIDCAuthProviderConfig;
52+
import SAMLAuthProviderConfig = auth.SAMLAuthProviderConfig;
53+
import OIDCUpdateAuthProviderRequest = auth.OIDCUpdateAuthProviderRequest;
54+
import SAMLUpdateAuthProviderRequest = auth.SAMLUpdateAuthProviderRequest;
55+
import CreateTenantRequest = auth.CreateTenantRequest;
56+
import UpdateTenantRequest = auth.UpdateTenantRequest;
4457

4558
/** Firebase Auth request header. */
4659
const FIREBASE_AUTH_HEADER = {
@@ -1523,7 +1536,7 @@ export abstract class AbstractAuthRequestHandler {
15231536
* @return {Promise<OIDCConfigServerResponse>} A promise that resolves with the newly created OIDC
15241537
* configuration.
15251538
*/
1526-
public createOAuthIdpConfig(options: AuthProviderConfig): Promise<OIDCConfigServerResponse> {
1539+
public createOAuthIdpConfig(options: OIDCAuthProviderConfig): Promise<OIDCConfigServerResponse> {
15271540
// Construct backend request.
15281541
let request;
15291542
try {
@@ -1646,7 +1659,7 @@ export abstract class AbstractAuthRequestHandler {
16461659
* @return {Promise<SAMLConfigServerResponse>} A promise that resolves with the newly created SAML
16471660
* configuration.
16481661
*/
1649-
public createInboundSamlConfig(options: AuthProviderConfig): Promise<SAMLConfigServerResponse> {
1662+
public createInboundSamlConfig(options: SAMLAuthProviderConfig): Promise<SAMLConfigServerResponse> {
16501663
// Construct backend request.
16511664
let request;
16521665
try {
@@ -1956,7 +1969,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
19561969
* @param {TenantOptions} tenantOptions The properties to set on the new tenant to be created.
19571970
* @return {Promise<TenantServerResponse>} A promise that resolves with the newly created tenant object.
19581971
*/
1959-
public createTenant(tenantOptions: TenantOptions): Promise<TenantServerResponse> {
1972+
public createTenant(tenantOptions: CreateTenantRequest): Promise<TenantServerResponse> {
19601973
try {
19611974
// Construct backend request.
19621975
const request = Tenant.buildServerRequest(tenantOptions, true);
@@ -1976,7 +1989,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler {
19761989
* @param {TenantOptions} tenantOptions The properties to update on the existing tenant.
19771990
* @return {Promise<TenantServerResponse>} A promise that resolves with the modified tenant object.
19781991
*/
1979-
public updateTenant(tenantId: string, tenantOptions: TenantOptions): Promise<TenantServerResponse> {
1992+
public updateTenant(tenantId: string, tenantOptions: UpdateTenantRequest): Promise<TenantServerResponse> {
19801993
if (!validator.isNonEmptyString(tenantId)) {
19811994
return Promise.reject(new FirebaseAuthError(AuthClientErrorCode.INVALID_TENANT_ID));
19821995
}

src/auth/auth-config.ts

Lines changed: 28 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,18 @@
1717
import * as validator from '../utils/validator';
1818
import { deepCopy } from '../utils/deep-copy';
1919
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
20+
import { auth } from './index';
21+
22+
import MultiFactorConfigInterface = auth.MultiFactorConfig;
23+
import MultiFactorConfigState = auth.MultiFactorConfigState;
24+
import AuthFactorType = auth.AuthFactorType;
25+
import EmailSignInProviderConfig = auth.EmailSignInProviderConfig;
26+
import OIDCAuthProviderConfig = auth.OIDCAuthProviderConfig;
27+
import SAMLAuthProviderConfig = auth.SAMLAuthProviderConfig;
2028

2129
/** A maximum of 10 test phone number / code pairs can be configured. */
2230
export const MAXIMUM_TEST_PHONE_NUMBERS = 10;
2331

24-
/** The filter interface used for listing provider configurations. */
25-
export interface AuthProviderConfigFilter {
26-
type: 'saml' | 'oidc';
27-
maxResults?: number;
28-
pageToken?: string;
29-
}
30-
31-
/** The base Auth provider configuration interface. */
32-
export interface AuthProviderConfig {
33-
providerId: string;
34-
displayName?: string;
35-
enabled: boolean;
36-
}
37-
38-
/** The OIDC Auth provider configuration interface. */
39-
export interface OIDCAuthProviderConfig extends AuthProviderConfig {
40-
clientId: string;
41-
issuer: string;
42-
}
43-
44-
/** The SAML Auth provider configuration interface. */
45-
export interface SAMLAuthProviderConfig extends AuthProviderConfig {
46-
idpEntityId: string;
47-
ssoURL: string;
48-
x509Certificates: string[];
49-
rpEntityId: string;
50-
callbackURL?: string;
51-
enableRequestSigning?: boolean;
52-
}
53-
5432
/** The server side SAML configuration request interface. */
5533
export interface SAMLConfigServerRequest {
5634
idpConfig?: {
@@ -111,107 +89,39 @@ export interface OIDCConfigServerResponse {
11189
enabled?: boolean;
11290
}
11391

114-
/** The public API response interface for listing provider configs. */
115-
export interface ListProviderConfigResults {
116-
providerConfigs: AuthProviderConfig[];
117-
pageToken?: string;
118-
}
119-
120-
/** The public API request interface for updating a SAML Auth provider. */
121-
export interface SAMLUpdateAuthProviderRequest {
122-
idpEntityId?: string;
123-
ssoURL?: string;
124-
x509Certificates?: string[];
125-
rpEntityId?: string;
126-
callbackURL?: string;
127-
enableRequestSigning?: boolean;
128-
enabled?: boolean;
129-
displayName?: string;
130-
}
131-
132-
/** The generic request interface for updating/creating a SAML Auth provider. */
133-
export interface SAMLAuthProviderRequest extends SAMLUpdateAuthProviderRequest {
134-
providerId?: string;
135-
}
136-
137-
/** The public API request interface for updating an OIDC Auth provider. */
138-
export interface OIDCUpdateAuthProviderRequest {
139-
clientId?: string;
140-
issuer?: string;
141-
enabled?: boolean;
142-
displayName?: string;
143-
}
144-
145-
/** The generic request interface for updating/creating an OIDC Auth provider. */
146-
export interface OIDCAuthProviderRequest extends OIDCUpdateAuthProviderRequest {
147-
providerId?: string;
148-
}
149-
150-
/** The public API request interface for updating a generic Auth provider. */
151-
export type UpdateAuthProviderRequest = SAMLUpdateAuthProviderRequest | OIDCUpdateAuthProviderRequest;
152-
153-
/** The email provider configuration interface. */
154-
export interface EmailSignInProviderConfig {
155-
enabled?: boolean;
156-
passwordRequired?: boolean; // In the backend API, default is true if not provided
157-
}
158-
15992
/** The server side email configuration request interface. */
16093
export interface EmailSignInConfigServerRequest {
16194
allowPasswordSignup?: boolean;
16295
enableEmailLinkSignin?: boolean;
16396
}
16497

165-
/** Identifies the public second factor type. */
166-
export type AuthFactorType = 'phone';
167-
16898
/** Identifies the server side second factor type. */
169-
export type AuthFactorServerType = 'PHONE_SMS';
99+
type AuthFactorServerType = 'PHONE_SMS';
170100

171101
/** Client Auth factor type to server auth factor type mapping. */
172-
export const AUTH_FACTOR_CLIENT_TO_SERVER_TYPE: {[key: string]: AuthFactorServerType} = {
102+
const AUTH_FACTOR_CLIENT_TO_SERVER_TYPE: {[key: string]: AuthFactorServerType} = {
173103
phone: 'PHONE_SMS',
174104
};
175105

176106
/** Server Auth factor type to client auth factor type mapping. */
177-
export const AUTH_FACTOR_SERVER_TO_CLIENT_TYPE: {[key: string]: AuthFactorType} =
107+
const AUTH_FACTOR_SERVER_TO_CLIENT_TYPE: {[key: string]: AuthFactorType} =
178108
Object.keys(AUTH_FACTOR_CLIENT_TO_SERVER_TYPE)
179109
.reduce((res: {[key: string]: AuthFactorType}, key) => {
180110
res[AUTH_FACTOR_CLIENT_TO_SERVER_TYPE[key]] = key as AuthFactorType;
181111
return res;
182112
}, {});
183113

184-
/** Identifies a multi-factor configuration state. */
185-
export type MultiFactorConfigState = 'ENABLED' | 'DISABLED';
186-
187-
/**
188-
* Public API interface representing a multi-factor configuration.
189-
*/
190-
export interface MultiFactorConfig {
191-
/**
192-
* The multi-factor config state.
193-
*/
194-
state: MultiFactorConfigState;
195-
196-
/**
197-
* The list of identifiers for enabled second factors.
198-
* Currently only ‘phone’ is supported.
199-
*/
200-
factorIds?: AuthFactorType[];
201-
}
202-
203114
/** Server side multi-factor configuration. */
204115
export interface MultiFactorAuthServerConfig {
205116
state?: MultiFactorConfigState;
206117
enabledProviders?: AuthFactorServerType[];
207118
}
208119

209-
210120
/**
211121
* Defines the multi-factor config class used to convert client side MultiFactorConfig
212122
* to a format that is understood by the Auth server.
213123
*/
214-
export class MultiFactorAuthConfig implements MultiFactorConfig {
124+
export class MultiFactorAuthConfig implements MultiFactorConfigInterface {
215125
public readonly state: MultiFactorConfigState;
216126
public readonly factorIds: AuthFactorType[];
217127

@@ -222,7 +132,7 @@ export class MultiFactorAuthConfig implements MultiFactorConfig {
222132
* @param options The options object to convert to a server request.
223133
* @return The resulting server request.
224134
*/
225-
public static buildServerRequest(options: MultiFactorConfig): MultiFactorAuthServerConfig {
135+
public static buildServerRequest(options: MultiFactorConfigInterface): MultiFactorAuthServerConfig {
226136
const request: MultiFactorAuthServerConfig = {};
227137
MultiFactorAuthConfig.validate(options);
228138
if (Object.prototype.hasOwnProperty.call(options, 'state')) {
@@ -248,7 +158,7 @@ export class MultiFactorAuthConfig implements MultiFactorConfig {
248158
*
249159
* @param options The options object to validate.
250160
*/
251-
private static validate(options: MultiFactorConfig): void {
161+
private static validate(options: MultiFactorConfigInterface): void {
252162
const validKeys = {
253163
state: true,
254164
factorIds: true,
@@ -492,7 +402,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
492402
* @return {?SAMLConfigServerRequest} The resulting server request or null if not valid.
493403
*/
494404
public static buildServerRequest(
495-
options: SAMLAuthProviderRequest,
405+
options: Partial<SAMLAuthProviderConfig>,
496406
ignoreMissingFields = false): SAMLConfigServerRequest | null {
497407
const makeRequest = validator.isNonNullObject(options) &&
498408
(options.providerId || ignoreMissingFields);
@@ -509,7 +419,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
509419
request.idpConfig = {
510420
idpEntityId: options.idpEntityId,
511421
ssoUrl: options.ssoURL,
512-
signRequest: options.enableRequestSigning,
422+
signRequest: (options as any).enableRequestSigning,
513423
idpCertificates: typeof options.x509Certificates === 'undefined' ? undefined : [],
514424
};
515425
if (options.x509Certificates) {
@@ -557,7 +467,7 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
557467
* @param {SAMLAuthProviderRequest} options The options object to validate.
558468
* @param {boolean=} ignoreMissingFields Whether to ignore missing fields.
559469
*/
560-
public static validate(options: SAMLAuthProviderRequest, ignoreMissingFields = false): void {
470+
public static validate(options: Partial<SAMLAuthProviderConfig>, ignoreMissingFields = false): void {
561471
const validKeys = {
562472
enabled: true,
563473
displayName: true,
@@ -643,8 +553,8 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
643553
);
644554
}
645555
});
646-
if (typeof options.enableRequestSigning !== 'undefined' &&
647-
!validator.isBoolean(options.enableRequestSigning)) {
556+
if (typeof (options as any).enableRequestSigning !== 'undefined' &&
557+
!validator.isBoolean((options as any).enableRequestSigning)) {
648558
throw new FirebaseAuthError(
649559
AuthClientErrorCode.INVALID_CONFIG,
650560
'"SAMLAuthProviderConfig.enableRequestSigning" must be a boolean.',
@@ -714,8 +624,8 @@ export class SAMLConfig implements SAMLAuthProviderConfig {
714624
this.displayName = response.displayName;
715625
}
716626

717-
/** @return {SAMLAuthProviderConfig} The plain object representation of the SAMLConfig. */
718-
public toJSON(): SAMLAuthProviderConfig {
627+
/** @return The plain object representation of the SAMLConfig. */
628+
public toJSON(): object {
719629
return {
720630
enabled: this.enabled,
721631
displayName: this.displayName,
@@ -747,12 +657,12 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
747657
* Throws an error if validation fails. If the request is not a OIDCConfig request,
748658
* returns null.
749659
*
750-
* @param {OIDCAuthProviderRequest} options The options object to convert to a server request.
751-
* @param {boolean=} ignoreMissingFields Whether to ignore missing fields.
752-
* @return {?OIDCConfigServerRequest} The resulting server request or null if not valid.
660+
* @param options The options object to convert to a server request.
661+
* @param ignoreMissingFields Whether to ignore missing fields.
662+
* @return The resulting server request or null if not valid.
753663
*/
754664
public static buildServerRequest(
755-
options: OIDCAuthProviderRequest,
665+
options: Partial<OIDCAuthProviderConfig>,
756666
ignoreMissingFields = false): OIDCConfigServerRequest | null {
757667
const makeRequest = validator.isNonNullObject(options) &&
758668
(options.providerId || ignoreMissingFields);
@@ -795,10 +705,10 @@ export class OIDCConfig implements OIDCAuthProviderConfig {
795705
/**
796706
* Validates the OIDCConfig options object. Throws an error on failure.
797707
*
798-
* @param {OIDCAuthProviderRequest} options The options object to validate.
799-
* @param {boolean=} ignoreMissingFields Whether to ignore missing fields.
708+
* @param options The options object to validate.
709+
* @param ignoreMissingFields Whether to ignore missing fields.
800710
*/
801-
public static validate(options: OIDCAuthProviderRequest, ignoreMissingFields = false): void {
711+
public static validate(options: Partial<OIDCAuthProviderConfig>, ignoreMissingFields = false): void {
802712
const validKeys = {
803713
enabled: true,
804714
displayName: true,

0 commit comments

Comments
 (0)