Skip to content

Commit f15bc95

Browse files
committed
Merge branch 'master' into fei-ref-update
2 parents ce014a0 + bd7277d commit f15bc95

File tree

12 files changed

+149
-64
lines changed

12 files changed

+149
-64
lines changed

common/api-review/auth-exp.api.md

+12-35
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,17 @@ export const debugErrorMap: AuthErrorMap;
185185
// @public
186186
export function deleteUser(user: User): Promise<void>;
187187

188-
// @public (undocumented)
188+
// @public
189189
export interface Dependencies {
190-
// (undocumented)
191190
errorMap?: AuthErrorMap;
192-
// (undocumented)
193191
persistence?: Persistence | Persistence[];
194-
// (undocumented)
195192
popupRedirectResolver?: PopupRedirectResolver;
196193
}
197194

198195
// @public
199196
export class EmailAuthCredential extends AuthCredential {
200-
// (undocumented)
201-
readonly email: string;
197+
// @internal (undocumented)
198+
readonly _email: string;
202199
// @internal (undocumented)
203200
static _fromEmailAndCode(email: string, oobCode: string, tenantId?: string | null): EmailAuthCredential;
204201
// @internal (undocumented)
@@ -210,10 +207,10 @@ export class EmailAuthCredential extends AuthCredential {
210207
_getReauthenticationResolver(auth: AuthInternal): Promise<IdTokenResponse>;
211208
// @internal (undocumented)
212209
_linkToIdToken(auth: AuthInternal, idToken: string): Promise<IdTokenResponse>;
213-
// (undocumented)
214-
readonly password: string;
215-
// (undocumented)
216-
readonly tenantId: string | null;
210+
// @internal (undocumented)
211+
readonly _password: string;
212+
// @internal (undocumented)
213+
readonly _tenantId: string | null;
217214
toJSON(): object;
218215
}
219216

@@ -301,7 +298,7 @@ export interface IdTokenResult {
301298
// @public
302299
export const indexedDBLocalPersistence: Persistence;
303300

304-
// @public (undocumented)
301+
// @public
305302
export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth;
306303

307304
// @public
@@ -397,7 +394,6 @@ export interface OAuthCredentialOptions {
397394
export class OAuthProvider extends BaseOAuthProvider {
398395
credential(params: OAuthCredentialOptions): OAuthCredential;
399396
static credentialFromError(error: FirebaseError): OAuthCredential | null;
400-
// (undocumented)
401397
static credentialFromJSON(json: object | string): OAuthCredential;
402398
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
403399
}
@@ -460,7 +456,6 @@ export class PhoneAuthCredential extends AuthCredential {
460456
export class PhoneAuthProvider {
461457
constructor(auth: Auth);
462458
static credential(verificationId: string, verificationCode: string): PhoneAuthCredential;
463-
// (undocumented)
464459
static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
465460
static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE;
466461
static readonly PROVIDER_ID = ProviderId.PHONE;
@@ -507,23 +502,17 @@ export const prodErrorMap: AuthErrorMap;
507502

508503
// @public
509504
export const enum ProviderId {
510-
// (undocumented)
505+
// @internal (undocumented)
511506
ANONYMOUS = "anonymous",
512-
// (undocumented)
507+
// @internal (undocumented)
513508
CUSTOM = "custom",
514-
// (undocumented)
515509
FACEBOOK = "facebook.com",
516-
// (undocumented)
510+
// @internal (undocumented)
517511
FIREBASE = "firebase",
518-
// (undocumented)
519512
GITHUB = "github.com",
520-
// (undocumented)
521513
GOOGLE = "google.com",
522-
// (undocumented)
523514
PASSWORD = "password",
524-
// (undocumented)
525515
PHONE = "phone",
526-
// (undocumented)
527516
TWITTER = "twitter.com"
528517
}
529518

@@ -572,11 +561,8 @@ export function reload(user: User): Promise<void>;
572561
// @public
573562
export class SAMLAuthProvider extends FederatedAuthProvider {
574563
constructor(providerId: string);
575-
// (undocumented)
576564
static credentialFromError(error: FirebaseError): AuthCredential | null;
577-
// (undocumented)
578565
static credentialFromJSON(json: string | object): AuthCredential;
579-
// (undocumented)
580566
static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
581567
}
582568

@@ -597,21 +583,14 @@ export function signInAnonymously(auth: Auth): Promise<UserCredential>;
597583

598584
// @public
599585
export const enum SignInMethod {
600-
// (undocumented)
586+
// @internal (undocumented)
601587
ANONYMOUS = "anonymous",
602-
// (undocumented)
603588
EMAIL_LINK = "emailLink",
604-
// (undocumented)
605589
EMAIL_PASSWORD = "password",
606-
// (undocumented)
607590
FACEBOOK = "facebook.com",
608-
// (undocumented)
609591
GITHUB = "github.com",
610-
// (undocumented)
611592
GOOGLE = "google.com",
612-
// (undocumented)
613593
PHONE = "phone",
614-
// (undocumented)
615594
TWITTER = "twitter.com"
616595
}
617596

@@ -645,9 +624,7 @@ export class TwitterAuthProvider extends BaseOAuthProvider {
645624
static credential(token: string, secret: string): OAuthCredential;
646625
static credentialFromError(error: FirebaseError): OAuthCredential | null;
647626
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
648-
// (undocumented)
649627
static readonly PROVIDER_ID = ProviderId.TWITTER;
650-
// (undocumented)
651628
static readonly TWITTER_SIGN_IN_METHOD = SignInMethod.TWITTER;
652629
}
653630

packages-exp/auth-exp/src/core/action_code_url.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export class ActionCodeURL {
154154
}
155155

156156
/**
157-
* {@inheritDoc ActionCodeURL.parseLink}
157+
* Parses the email action link string and returns an {@link ActionCodeURL} if
158+
* the link is valid, otherwise returns null.
158159
*
159160
* @public
160161
*/

packages-exp/auth-exp/src/core/auth/initialize.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,31 @@ import { _fail } from '../util/assert';
2424
import { _getInstance } from '../util/instantiator';
2525
import { AuthImpl } from './auth_impl';
2626

27-
/** @public */
27+
/**
28+
* Initializes an Auth instance with fine-grained control over
29+
* {@link Dependencies}.
30+
*
31+
* @remarks
32+
*
33+
* This function allows more control over the Auth instance than
34+
* {@link getAuth}. `getAuth` uses platform-specific defaults to supply
35+
* the {@link Dependencies}. In general, `getAuth` is the easiest way to
36+
* initialize Auth and works for most use cases. Use `initializeAuth` if you
37+
* need control over which persistence layer is used, or to minimize bundle
38+
* size if you're not using either `signInWithPopup` or `signInWithRedirect`.
39+
*
40+
* For example, if your app only uses anonymous accounts and you only want
41+
* accounts saved for the current session, initialize Auth with:
42+
*
43+
* ```js
44+
* const auth = initializeAuth(app, {
45+
* persistence: browserSessionPersistence,
46+
* popupRedirectResolver: undefined,
47+
* });
48+
* ```
49+
*
50+
* @public
51+
*/
2852
export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {
2953
const provider = _getProvider(app, 'auth-exp');
3054

packages-exp/auth-exp/src/core/credentials/email.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ import { AuthCredential } from './auth_credential';
4242
export class EmailAuthCredential extends AuthCredential {
4343
/** @internal */
4444
private constructor(
45-
readonly email: string,
46-
readonly password: string,
45+
/** @internal */
46+
readonly _email: string,
47+
/** @internal */
48+
readonly _password: string,
4749
signInMethod: SignInMethod,
48-
readonly tenantId: string | null = null
50+
/** @internal */
51+
readonly _tenantId: string | null = null
4952
) {
5053
super(ProviderId.PASSWORD, signInMethod);
5154
}
@@ -79,10 +82,10 @@ export class EmailAuthCredential extends AuthCredential {
7982
/** {@inheritdoc AuthCredential.toJSON} */
8083
toJSON(): object {
8184
return {
82-
email: this.email,
83-
password: this.password,
85+
email: this._email,
86+
password: this._password,
8487
signInMethod: this.signInMethod,
85-
tenantId: this.tenantId
88+
tenantId: this._tenantId
8689
};
8790
}
8891

@@ -112,13 +115,13 @@ export class EmailAuthCredential extends AuthCredential {
112115
case SignInMethod.EMAIL_PASSWORD:
113116
return signInWithPassword(auth, {
114117
returnSecureToken: true,
115-
email: this.email,
116-
password: this.password
118+
email: this._email,
119+
password: this._password
117120
});
118121
case SignInMethod.EMAIL_LINK:
119122
return signInWithEmailLink(auth, {
120-
email: this.email,
121-
oobCode: this.password
123+
email: this._email,
124+
oobCode: this._password
122125
});
123126
default:
124127
_fail(auth, AuthErrorCode.INTERNAL_ERROR);
@@ -135,14 +138,14 @@ export class EmailAuthCredential extends AuthCredential {
135138
return updateEmailPassword(auth, {
136139
idToken,
137140
returnSecureToken: true,
138-
email: this.email,
139-
password: this.password
141+
email: this._email,
142+
password: this._password
140143
});
141144
case SignInMethod.EMAIL_LINK:
142145
return signInWithEmailLinkForLinking(auth, {
143146
idToken,
144-
email: this.email,
145-
oobCode: this.password
147+
email: this._email,
148+
oobCode: this._password
146149
});
147150
default:
148151
_fail(auth, AuthErrorCode.INTERNAL_ERROR);

packages-exp/auth-exp/src/core/credentials/phone.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,7 @@ export class PhoneAuthCredential extends AuthCredential {
121121
return obj;
122122
}
123123

124-
/**
125-
* Static method to deserialize a JSON representation of an object into an {@link AuthCredential}.
126-
*
127-
* @param json - Either `object` or the stringified representation of the object. When string is
128-
* provided, `JSON.parse` would be called first.
129-
*
130-
* @returns If the JSON input does not represent an {@link AuthCredential}, null is returned.
131-
*/
124+
/** Generates a phone credential based on a plain object or a JSON string. */
132125
static fromJSON(json: object | string): PhoneAuthCredential | null {
133126
if (typeof json === 'string') {
134127
json = JSON.parse(json);

packages-exp/auth-exp/src/core/providers/email.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ describe('core/providers/email', () => {
3333
'some-email',
3434
'some-password'
3535
);
36-
expect(credential.email).to.eq('some-email');
37-
expect(credential.password).to.eq('some-password');
36+
expect(credential._email).to.eq('some-email');
37+
expect(credential._password).to.eq('some-password');
3838
expect(credential.providerId).to.eq(ProviderId.PASSWORD);
3939
expect(credential.signInMethod).to.eq(SignInMethod.EMAIL_PASSWORD);
4040
});
@@ -54,8 +54,8 @@ describe('core/providers/email', () => {
5454
'some-email',
5555
actionLink
5656
);
57-
expect(credential.email).to.eq('some-email');
58-
expect(credential.password).to.eq('CODE');
57+
expect(credential._email).to.eq('some-email');
58+
expect(credential._password).to.eq('CODE');
5959
expect(credential.providerId).to.eq(ProviderId.PASSWORD);
6060
expect(credential.signInMethod).to.eq(SignInMethod.EMAIL_LINK);
6161
});

packages-exp/auth-exp/src/core/providers/oauth.ts

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export abstract class BaseOAuthProvider
128128
* @public
129129
*/
130130
export class OAuthProvider extends BaseOAuthProvider {
131+
/**
132+
* Creates an {@link OAuthCredential} from a JSON string or a plain object.
133+
* @param json A plain object or a JSON string
134+
*/
131135
static credentialFromJSON(json: object | string): OAuthCredential {
132136
const obj = typeof json === 'string' ? JSON.parse(json) : json;
133137
_assert(

packages-exp/auth-exp/src/core/providers/saml.ts

+26
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ export class SAMLAuthProvider extends FederatedAuthProvider {
4646
super(providerId);
4747
}
4848

49+
/**
50+
* Generates an {@link AuthCredential} from a {@link UserCredential} after a
51+
* successful SAML flow completes.
52+
*
53+
* @remarks
54+
*
55+
* For example, to get an {@link AuthCredential}, you could write the
56+
* following code:
57+
*
58+
* ```js
59+
* const userCredential = await signInWithPopup(auth, samlProvider);
60+
* const credential = SAMLAuthProvider.credentialFromResult(userCredential);
61+
* ```
62+
*
63+
* @param userCredential
64+
*/
4965
static credentialFromResult(
5066
userCredential: UserCredential
5167
): AuthCredential | null {
@@ -54,12 +70,22 @@ export class SAMLAuthProvider extends FederatedAuthProvider {
5470
);
5571
}
5672

73+
/**
74+
* Used to extract the underlying {@link OAuthCredential} from a {@link AuthError} which was
75+
* thrown during a sign-in, link, or reauthenticate operation.
76+
*
77+
* @param userCredential - The user credential.
78+
*/
5779
static credentialFromError(error: FirebaseError): AuthCredential | null {
5880
return SAMLAuthProvider.samlCredentialFromTaggedObject(
5981
(error.customData || {}) as TaggedWithTokenResponse
6082
);
6183
}
6284

85+
/**
86+
* Creates an {@link AuthCredential} from a JSON string or a plain object.
87+
* @param json A plain object or a JSON string
88+
*/
6389
static credentialFromJSON(json: string | object): AuthCredential {
6490
const credential = SAMLAuthCredential.fromJSON(json);
6591
_assert(credential, AuthErrorCode.ARGUMENT_ERROR);

packages-exp/auth-exp/src/core/providers/twitter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ import { BaseOAuthProvider } from './oauth';
8585
* @public
8686
*/
8787
export class TwitterAuthProvider extends BaseOAuthProvider {
88+
/** Always set to {@link SignInMethod.TWITTER}. */
8889
static readonly TWITTER_SIGN_IN_METHOD = SignInMethod.TWITTER;
90+
/** Always set to {@link ProviderId.TWITTER}. */
8991
static readonly PROVIDER_ID = ProviderId.TWITTER;
9092

9193
constructor() {

packages-exp/auth-exp/src/core/strategies/email_link.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export async function signInWithEmailLink(
155155
// Check if the tenant ID in the email link matches the tenant ID on Auth
156156
// instance.
157157
_assert(
158-
credential.tenantId === (authModular.tenantId || null),
158+
credential._tenantId === (authModular.tenantId || null),
159159
authModular,
160160
AuthErrorCode.TENANT_ID_MISMATCH
161161
);

0 commit comments

Comments
 (0)