Skip to content

Commit 19483c5

Browse files
committed
PR feedback
1 parent b7da2a3 commit 19483c5

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

packages-exp/auth-exp/src/core/credentials/inferred.test.ts renamed to packages-exp/auth-exp/src/core/credentials/from_token_response.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2019 Google Inc.
3+
* Copyright 2020 Google LLC.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import { expect } from 'chai';
2020
import { ProviderId } from '@firebase/auth-types-exp';
2121

2222
import { TEST_ID_TOKEN_RESPONSE } from '../../../test/id_token_response';
23-
import { _authCredentialFromTokenResponse } from './inferred';
23+
import { _authCredentialFromTokenResponse } from './from_token_response';
2424

2525
describe('src/core/credentials/inferred', () => {
2626
it('returns a phone credential if response conains correct fields', () => {

packages-exp/auth-exp/src/core/credentials/inferred.ts renamed to packages-exp/auth-exp/src/core/credentials/from_token_response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2020 Google LLC
3+
* Copyright 2020 Google LLC.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
import { OperationType } from '@firebase/auth-types-exp';
1919

20-
import { signInWithIdp, SignInWithIdpRequest } from '../../api/authentication/idp';
20+
import {
21+
signInWithIdp, SignInWithIdpRequest, SignInWithIdpResponse
22+
} from '../../api/authentication/idp';
2123
import { Auth } from '../../model/auth';
2224
import { User, UserCredential } from '../../model/user';
23-
import { _authCredentialFromTokenResponse } from '../credentials/inferred';
25+
import { _authCredentialFromTokenResponse } from '../credentials/from_token_response';
2426
import { _link as _linkUser } from '../user/link_unlink';
2527
import { _reauthenticate } from '../user/reauthenticate';
2628
import { UserCredentialImpl } from '../user/user_credential_impl';
@@ -38,28 +40,35 @@ export interface IdpTaskParams {
3840

3941
export type IdpTask = (params: IdpTaskParams) => Promise<UserCredential>;
4042

41-
function paramsToRequest({
43+
function callIdpSignIn(
44+
{
45+
auth,
4246
requestUri,
4347
sessionId,
4448
tenantId,
4549
pendingToken,
4650
postBody
47-
}: IdpTaskParams): SignInWithIdpRequest {
48-
return {
51+
}: IdpTaskParams, idToken?: string): Promise<SignInWithIdpResponse> {
52+
const request: SignInWithIdpRequest = {
4953
requestUri,
5054
sessionId,
5155
postBody: postBody || null,
5256
tenantId,
5357
pendingToken,
5458
returnSecureToken: true
5559
};
60+
61+
if (idToken) {
62+
request.idToken = idToken;
63+
}
64+
65+
return signInWithIdp(auth, request);
5666
}
5767

5868
export async function _signIn(params: IdpTaskParams): Promise<UserCredential> {
59-
const request = paramsToRequest(params);
6069
const auth = params.auth;
6170

62-
const response = await signInWithIdp(auth, request);
71+
const response = await callIdpSignIn(params);
6372

6473
const credential = _authCredentialFromTokenResponse(response);
6574
const userCredential = await UserCredentialImpl._fromIdTokenResponse(
@@ -75,16 +84,14 @@ export async function _signIn(params: IdpTaskParams): Promise<UserCredential> {
7584
export async function _reauth(params: IdpTaskParams): Promise<UserCredential> {
7685
const { auth, user } = params;
7786
assert(user, auth.name);
78-
const requestPromise = signInWithIdp(auth, paramsToRequest(params));
87+
const requestPromise = callIdpSignIn(params);
7988
return _reauthenticate(user, requestPromise);
8089
}
8190

8291
export async function _link(params: IdpTaskParams): Promise<UserCredential> {
8392
const { auth, user } = params;
8493
assert(user, auth.name);
85-
86-
const request = paramsToRequest(params);
87-
request.idToken = await user.getIdToken();
94+
const idToken = await user.getIdToken();
8895

89-
return _linkUser(user, signInWithIdp(auth, request));
96+
return _linkUser(user, callIdpSignIn(params, idToken));
9097
}

packages-exp/auth-exp/src/core/user/user_credential_impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Auth } from '../../model/auth';
2222
import { IdTokenResponse } from '../../model/id_token';
2323
import { User, UserCredential } from '../../model/user';
2424
import { AuthCredential } from '../credentials';
25-
import { _authCredentialFromTokenResponse } from '../credentials/inferred';
25+
import { _authCredentialFromTokenResponse } from '../credentials/from_token_response';
2626
import { UserImpl } from './user_impl';
2727

2828
export class UserCredentialImpl implements UserCredential {

0 commit comments

Comments
 (0)