Skip to content

Commit 95c1dc0

Browse files
authored
Merge e47c732 into f24d896
2 parents f24d896 + e47c732 commit 95c1dc0

File tree

12 files changed

+152
-63
lines changed

12 files changed

+152
-63
lines changed

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

Lines changed: 15 additions & 41 deletions
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

@@ -253,7 +250,7 @@ export function fetchSignInMethodsForEmail(auth: Auth, email: string): Promise<s
253250
export function getAdditionalUserInfo(userCredential: UserCredential): AdditionalUserInfo | null;
254251

255252
// @public
256-
export function getAuth(app: FirebaseApp): Auth;
253+
export function getAuth(app?: FirebaseApp): Auth;
257254

258255
// @public
259256
export function getIdToken(user: User, forceRefresh?: boolean): Promise<string>;
@@ -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
}
@@ -415,7 +411,7 @@ export const enum OperationType {
415411
SIGN_IN = "signIn"
416412
}
417413

418-
// @public (undocumented)
414+
// @public
419415
export function parseActionCodeURL(link: string): ActionCodeURL | null;
420416

421417
// @public
@@ -438,9 +434,6 @@ export interface Persistence {
438434

439435
// @public
440436
export class PhoneAuthCredential extends AuthCredential {
441-
// Warning: (ae-unresolved-inheritdoc-reference) The @inheritDoc reference could not be resolved: No member was found with name "fromJSON"
442-
//
443-
// (undocumented)
444437
static fromJSON(json: object | string): PhoneAuthCredential | null;
445438
// @internal (undocumented)
446439
static _fromTokenResponse(phoneNumber: string, temporaryProof: string): PhoneAuthCredential;
@@ -463,7 +456,6 @@ export class PhoneAuthCredential extends AuthCredential {
463456
export class PhoneAuthProvider {
464457
constructor(auth: Auth);
465458
static credential(verificationId: string, verificationCode: string): PhoneAuthCredential;
466-
// (undocumented)
467459
static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
468460
static readonly PHONE_SIGN_IN_METHOD = SignInMethod.PHONE;
469461
static readonly PROVIDER_ID = ProviderId.PHONE;
@@ -510,23 +502,17 @@ export const prodErrorMap: AuthErrorMap;
510502

511503
// @public
512504
export const enum ProviderId {
513-
// (undocumented)
505+
// @internal (undocumented)
514506
ANONYMOUS = "anonymous",
515-
// (undocumented)
507+
// @internal (undocumented)
516508
CUSTOM = "custom",
517-
// (undocumented)
518509
FACEBOOK = "facebook.com",
519-
// (undocumented)
510+
// @internal (undocumented)
520511
FIREBASE = "firebase",
521-
// (undocumented)
522512
GITHUB = "github.com",
523-
// (undocumented)
524513
GOOGLE = "google.com",
525-
// (undocumented)
526514
PASSWORD = "password",
527-
// (undocumented)
528515
PHONE = "phone",
529-
// (undocumented)
530516
TWITTER = "twitter.com"
531517
}
532518

@@ -575,11 +561,8 @@ export function reload(user: User): Promise<void>;
575561
// @public
576562
export class SAMLAuthProvider extends FederatedAuthProvider {
577563
constructor(providerId: string);
578-
// (undocumented)
579564
static credentialFromError(error: FirebaseError): AuthCredential | null;
580-
// (undocumented)
581565
static credentialFromJSON(json: string | object): AuthCredential;
582-
// (undocumented)
583566
static credentialFromResult(userCredential: UserCredential): AuthCredential | null;
584567
}
585568

@@ -590,7 +573,7 @@ export function sendEmailVerification(user: User, actionCodeSettings?: ActionCod
590573
export function sendPasswordResetEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;
591574

592575
// @public
593-
export function sendSignInLinkToEmail(auth: Auth, email: string, actionCodeSettings?: ActionCodeSettings): Promise<void>;
576+
export function sendSignInLinkToEmail(auth: Auth, email: string, actionCodeSettings: ActionCodeSettings): Promise<void>;
594577

595578
// @public
596579
export function setPersistence(auth: Auth, persistence: Persistence): Promise<void>;
@@ -600,21 +583,14 @@ export function signInAnonymously(auth: Auth): Promise<UserCredential>;
600583

601584
// @public
602585
export const enum SignInMethod {
603-
// (undocumented)
586+
// @internal (undocumented)
604587
ANONYMOUS = "anonymous",
605-
// (undocumented)
606588
EMAIL_LINK = "emailLink",
607-
// (undocumented)
608589
EMAIL_PASSWORD = "password",
609-
// (undocumented)
610590
FACEBOOK = "facebook.com",
611-
// (undocumented)
612591
GITHUB = "github.com",
613-
// (undocumented)
614592
GOOGLE = "google.com",
615-
// (undocumented)
616593
PHONE = "phone",
617-
// (undocumented)
618594
TWITTER = "twitter.com"
619595
}
620596

@@ -648,9 +624,7 @@ export class TwitterAuthProvider extends BaseOAuthProvider {
648624
static credential(token: string, secret: string): OAuthCredential;
649625
static credentialFromError(error: FirebaseError): OAuthCredential | null;
650626
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
651-
// (undocumented)
652627
static readonly PROVIDER_ID = ProviderId.TWITTER;
653-
// (undocumented)
654628
static readonly TWITTER_SIGN_IN_METHOD = SignInMethod.TWITTER;
655629
}
656630

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export class ActionCodeURL {
154154
}
155155

156156
/**
157-
* {@inheritDoc @firebase/auth-types#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

Lines changed: 25 additions & 1 deletion
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

Lines changed: 17 additions & 14 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class PhoneAuthCredential extends AuthCredential {
121121
return obj;
122122
}
123123

124-
/** {@inheritdoc AuthCredential.fromJSON} */
124+
/** Generates a phone credential based on a plain object or a JSON string. */
125125
static fromJSON(json: object | string): PhoneAuthCredential | null {
126126
if (typeof json === 'string') {
127127
json = JSON.parse(json);

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)