File tree 6 files changed +30
-11
lines changed
6 files changed +30
-11
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @firebase/auth " : patch
3
+ ---
4
+
5
+ Fix bug in the ` OAuthProvider.prototype.credential ` method that was preventing the ` rawNonce ` field from being populated in the returned ` OAuthCredential ` .
Original file line number Diff line number Diff line change @@ -493,8 +493,6 @@ export class OAuthCredential extends AuthCredential {
493
493
idToken? : string ;
494
494
// @internal (undocumented)
495
495
_linkToIdToken(auth : AuthInternal , idToken : string ): Promise <IdTokenResponse >;
496
- // @internal (undocumented)
497
- nonce? : string ;
498
496
secret? : string ;
499
497
toJSON(): object ;
500
498
}
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ describe('core/credentials/oauth', () => {
69
69
nonce : 'nonce'
70
70
} ) ;
71
71
72
- expect ( cred . nonce ) . to . eq ( 'nonce' ) ;
72
+ expect ( ( cred . toJSON ( ) as { nonce : string } ) . nonce ) . to . eq ( 'nonce' ) ;
73
73
} ) ;
74
74
75
75
it ( 'ignores the nonce if pendingToken set' , ( ) => {
@@ -81,7 +81,7 @@ describe('core/credentials/oauth', () => {
81
81
pendingToken : 'pending-token'
82
82
} ) ;
83
83
84
- expect ( cred . nonce ) . to . be . undefined ;
84
+ expect ( ( cred . toJSON ( ) as { nonce ?: string } ) . nonce ) . to . be . undefined ;
85
85
} ) ;
86
86
87
87
it ( 'handles oauth1 and oauth with token secret' , ( ) => {
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ export class OAuthCredential extends AuthCredential {
75
75
* @readonly
76
76
*/
77
77
secret ?: string ;
78
- /** @internal */
79
- nonce ?: string ;
78
+
79
+ private nonce ?: string ;
80
80
private pendingToken : string | null = null ;
81
81
82
82
/** @internal */
@@ -136,13 +136,17 @@ export class OAuthCredential extends AuthCredential {
136
136
*/
137
137
static fromJSON ( json : string | object ) : OAuthCredential | null {
138
138
const obj = typeof json === 'string' ? JSON . parse ( json ) : json ;
139
- const { providerId, signInMethod, ...rest } : Partial < OAuthCredential > = obj ;
139
+ const { providerId, signInMethod, ...rest } : OAuthCredentialParams = obj ;
140
140
if ( ! providerId || ! signInMethod ) {
141
141
return null ;
142
142
}
143
143
144
144
const cred = new OAuthCredential ( providerId , signInMethod ) ;
145
- Object . assign ( cred , rest ) ;
145
+ cred . idToken = rest . idToken || undefined ;
146
+ cred . accessToken = rest . accessToken || undefined ;
147
+ cred . secret = rest . secret ;
148
+ cred . nonce = rest . nonce ;
149
+ cred . pendingToken = rest . pendingToken || null ;
146
150
return cred ;
147
151
}
148
152
Original file line number Diff line number Diff line change @@ -117,4 +117,16 @@ describe('core/providers/oauth', () => {
117
117
expect ( cred . providerId ) . to . eq ( ProviderId . FACEBOOK ) ;
118
118
expect ( cred . signInMethod ) . to . eq ( SignInMethod . FACEBOOK ) ;
119
119
} ) ;
120
+
121
+ it ( 'credential generates the cred with the correct fields' , ( ) => {
122
+ const provider = new OAuthProvider ( 'foo.test' ) ;
123
+ const cred = provider . credential ( {
124
+ idToken : 'foo' ,
125
+ rawNonce : 'i-am-a-nonce' ,
126
+ } ) ;
127
+ expect ( cred . idToken ) . to . eq ( 'foo' ) ;
128
+ expect ( cred . providerId ) . to . eq ( 'foo.test' ) ;
129
+ expect ( cred . signInMethod ) . to . eq ( 'foo.test' ) ;
130
+ expect ( ( cred . toJSON ( ) as { nonce : string } ) . nonce ) . to . eq ( 'i-am-a-nonce' ) ;
131
+ } ) ;
120
132
} ) ;
Original file line number Diff line number Diff line change @@ -164,12 +164,12 @@ export class OAuthProvider extends BaseOAuthProvider {
164
164
* or the ID token string.
165
165
*/
166
166
credential ( params : OAuthCredentialOptions ) : OAuthCredential {
167
- return this . _credential ( params ) ;
167
+ return this . _credential ( { ... params , nonce : params . rawNonce } ) ;
168
168
}
169
169
170
170
/** An internal credential method that accepts more permissive options */
171
171
private _credential (
172
- params : OAuthCredentialOptions | OAuthCredentialParams
172
+ params : Omit < OAuthCredentialParams , 'signInMethod' | 'providerId' >
173
173
) : OAuthCredential {
174
174
_assert ( params . idToken || params . accessToken , AuthErrorCode . ARGUMENT_ERROR ) ;
175
175
// For OAuthCredential, sign in method is same as providerId.
@@ -236,7 +236,7 @@ export class OAuthProvider extends BaseOAuthProvider {
236
236
return new OAuthProvider ( providerId ) . _credential ( {
237
237
idToken : oauthIdToken ,
238
238
accessToken : oauthAccessToken ,
239
- rawNonce : nonce ,
239
+ nonce,
240
240
pendingToken
241
241
} ) ;
242
242
} catch ( e ) {
You can’t perform that action at this time.
0 commit comments