@@ -1143,9 +1143,9 @@ describe('phant auth adapter', () => {
1143
1143
auth : {
1144
1144
phantauth : {
1145
1145
enableInsecureAuth : true ,
1146
- }
1147
- }
1148
- } )
1146
+ } ,
1147
+ } ,
1148
+ } ) ;
1149
1149
const authData = {
1150
1150
id : 'fakeid' ,
1151
1151
access_token : 'sometoken' ,
@@ -1218,26 +1218,29 @@ describe('facebook limited auth adapter', () => {
1218
1218
}
1219
1219
} ) ;
1220
1220
1221
- it_id ( '7bfa55ab-8fd7-4526-992e-6de3df16bf9c' ) ( it ) ( 'should use algorithm from key header to verify id_token (facebook.com)' , async ( ) => {
1222
- const fakeClaim = {
1223
- iss : 'https://www.facebook.com' ,
1224
- aud : 'secret' ,
1225
- exp : Date . now ( ) ,
1226
- sub : 'the_user_id' ,
1227
- } ;
1228
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1229
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1230
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
1231
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1232
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1221
+ it_id ( '7bfa55ab-8fd7-4526-992e-6de3df16bf9c' ) ( it ) (
1222
+ 'should use algorithm from key header to verify id_token (facebook.com)' ,
1223
+ async ( ) => {
1224
+ const fakeClaim = {
1225
+ iss : 'https://www.facebook.com' ,
1226
+ aud : 'secret' ,
1227
+ exp : Date . now ( ) ,
1228
+ sub : 'the_user_id' ,
1229
+ } ;
1230
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1231
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1232
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
1233
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1234
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1233
1235
1234
- const result = await facebook . validateAuthData (
1235
- { id : 'the_user_id' , token : 'the_token' } ,
1236
- { clientId : 'secret' }
1237
- ) ;
1238
- expect ( result ) . toEqual ( fakeClaim ) ;
1239
- expect ( jwt . verify . calls . first ( ) . args [ 2 ] . algorithms ) . toEqual ( fakeDecodedToken . header . alg ) ;
1240
- } ) ;
1236
+ const result = await facebook . validateAuthData (
1237
+ { id : 'the_user_id' , token : 'the_token' } ,
1238
+ { clientId : 'secret' }
1239
+ ) ;
1240
+ expect ( result ) . toEqual ( fakeClaim ) ;
1241
+ expect ( jwt . verify . calls . first ( ) . args [ 2 ] . algorithms ) . toEqual ( fakeDecodedToken . header . alg ) ;
1242
+ }
1243
+ ) ;
1241
1244
1242
1245
it ( 'should not verify invalid id_token' , async ( ) => {
1243
1246
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
@@ -1268,89 +1271,101 @@ describe('facebook limited auth adapter', () => {
1268
1271
}
1269
1272
} ) ;
1270
1273
1271
- it_id ( '4bcb1a1a-11f8-4e12-a3f6-73f7e25e355a' ) ( it ) ( 'using client id as string) should verify id_token (facebook.com)' , async ( ) => {
1272
- const fakeClaim = {
1273
- iss : 'https://www.facebook.com' ,
1274
- aud : 'secret' ,
1275
- exp : Date . now ( ) ,
1276
- sub : 'the_user_id' ,
1277
- } ;
1278
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1279
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1280
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1281
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1282
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1283
-
1284
- const result = await facebook . validateAuthData (
1285
- { id : 'the_user_id' , token : 'the_token' } ,
1286
- { clientId : 'secret' }
1287
- ) ;
1288
- expect ( result ) . toEqual ( fakeClaim ) ;
1289
- } ) ;
1290
-
1291
- it_id ( 'c521a272-2ac2-4d8b-b5ed-ea250336d8b1' ) ( it ) ( '(using client id as array) should verify id_token (facebook.com)' , async ( ) => {
1292
- const fakeClaim = {
1293
- iss : 'https://www.facebook.com' ,
1294
- aud : 'secret' ,
1295
- exp : Date . now ( ) ,
1296
- sub : 'the_user_id' ,
1297
- } ;
1298
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1299
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1300
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1301
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1302
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1303
-
1304
- const result = await facebook . validateAuthData (
1305
- { id : 'the_user_id' , token : 'the_token' } ,
1306
- { clientId : [ 'secret' ] }
1307
- ) ;
1308
- expect ( result ) . toEqual ( fakeClaim ) ;
1309
- } ) ;
1310
-
1311
- it_id ( 'e3f16404-18e9-4a87-a555-4710cfbdac67' ) ( it ) ( '(using client id as array with multiple items) should verify id_token (facebook.com)' , async ( ) => {
1312
- const fakeClaim = {
1313
- iss : 'https://www.facebook.com' ,
1314
- aud : 'secret' ,
1315
- exp : Date . now ( ) ,
1316
- sub : 'the_user_id' ,
1317
- } ;
1318
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1319
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1320
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1321
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1322
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1323
-
1324
- const result = await facebook . validateAuthData (
1325
- { id : 'the_user_id' , token : 'the_token' } ,
1326
- { clientId : [ 'secret' , 'secret 123' ] }
1327
- ) ;
1328
- expect ( result ) . toEqual ( fakeClaim ) ;
1329
- } ) ;
1330
-
1331
- it_id ( '549c33a1-3a6b-4732-8cf6-8f010ad4569c' ) ( it ) ( '(using client id as string) should throw error with with invalid jwt issuer (facebook.com)' , async ( ) => {
1332
- const fakeClaim = {
1333
- iss : 'https://not.facebook.com' ,
1334
- sub : 'the_user_id' ,
1335
- } ;
1336
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1337
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1338
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1339
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1340
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1341
-
1342
- try {
1343
- await facebook . validateAuthData (
1274
+ it_id ( '4bcb1a1a-11f8-4e12-a3f6-73f7e25e355a' ) ( it ) (
1275
+ 'using client id as string) should verify id_token (facebook.com)' ,
1276
+ async ( ) => {
1277
+ const fakeClaim = {
1278
+ iss : 'https://www.facebook.com' ,
1279
+ aud : 'secret' ,
1280
+ exp : Date . now ( ) ,
1281
+ sub : 'the_user_id' ,
1282
+ } ;
1283
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1284
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1285
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1286
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1287
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1288
+
1289
+ const result = await facebook . validateAuthData (
1344
1290
{ id : 'the_user_id' , token : 'the_token' } ,
1345
1291
{ clientId : 'secret' }
1346
1292
) ;
1347
- fail ( ) ;
1348
- } catch ( e ) {
1349
- expect ( e . message ) . toBe (
1350
- 'id token not issued by correct OpenID provider - expected: https://www.facebook.com | from: https://not.facebook.com'
1293
+ expect ( result ) . toEqual ( fakeClaim ) ;
1294
+ }
1295
+ ) ;
1296
+
1297
+ it_id ( 'c521a272-2ac2-4d8b-b5ed-ea250336d8b1' ) ( it ) (
1298
+ '(using client id as array) should verify id_token (facebook.com)' ,
1299
+ async ( ) => {
1300
+ const fakeClaim = {
1301
+ iss : 'https://www.facebook.com' ,
1302
+ aud : 'secret' ,
1303
+ exp : Date . now ( ) ,
1304
+ sub : 'the_user_id' ,
1305
+ } ;
1306
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1307
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1308
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1309
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1310
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1311
+
1312
+ const result = await facebook . validateAuthData (
1313
+ { id : 'the_user_id' , token : 'the_token' } ,
1314
+ { clientId : [ 'secret' ] }
1351
1315
) ;
1316
+ expect ( result ) . toEqual ( fakeClaim ) ;
1352
1317
}
1353
- } ) ;
1318
+ ) ;
1319
+
1320
+ it_id ( 'e3f16404-18e9-4a87-a555-4710cfbdac67' ) ( it ) (
1321
+ '(using client id as array with multiple items) should verify id_token (facebook.com)' ,
1322
+ async ( ) => {
1323
+ const fakeClaim = {
1324
+ iss : 'https://www.facebook.com' ,
1325
+ aud : 'secret' ,
1326
+ exp : Date . now ( ) ,
1327
+ sub : 'the_user_id' ,
1328
+ } ;
1329
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1330
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1331
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1332
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1333
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1334
+
1335
+ const result = await facebook . validateAuthData (
1336
+ { id : 'the_user_id' , token : 'the_token' } ,
1337
+ { clientId : [ 'secret' , 'secret 123' ] }
1338
+ ) ;
1339
+ expect ( result ) . toEqual ( fakeClaim ) ;
1340
+ }
1341
+ ) ;
1342
+
1343
+ it_id ( '549c33a1-3a6b-4732-8cf6-8f010ad4569c' ) ( it ) (
1344
+ '(using client id as string) should throw error with with invalid jwt issuer (facebook.com)' ,
1345
+ async ( ) => {
1346
+ const fakeClaim = {
1347
+ iss : 'https://not.facebook.com' ,
1348
+ sub : 'the_user_id' ,
1349
+ } ;
1350
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1351
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1352
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1353
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1354
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1355
+
1356
+ try {
1357
+ await facebook . validateAuthData (
1358
+ { id : 'the_user_id' , token : 'the_token' } ,
1359
+ { clientId : 'secret' }
1360
+ ) ;
1361
+ fail ( ) ;
1362
+ } catch ( e ) {
1363
+ expect ( e . message ) . toBe (
1364
+ 'id token not issued by correct OpenID provider - expected: https://www.facebook.com | from: https://not.facebook.com'
1365
+ ) ;
1366
+ }
1367
+ }
1368
+ ) ;
1354
1369
1355
1370
// TODO: figure out a way to generate our own facebook signed tokens, perhaps with a parse facebook account
1356
1371
// and a private key
@@ -1459,28 +1474,31 @@ describe('facebook limited auth adapter', () => {
1459
1474
}
1460
1475
} ) ;
1461
1476
1462
- it_id ( 'c194d902-e697-46c9-a303-82c2d914473c' ) ( it ) ( 'should throw error with with invalid user id (facebook.com)' , async ( ) => {
1463
- const fakeClaim = {
1464
- iss : 'https://www.facebook.com' ,
1465
- aud : 'invalid_client_id' ,
1466
- sub : 'a_different_user_id' ,
1467
- } ;
1468
- const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1469
- const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1470
- spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1471
- spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1472
- spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1473
-
1474
- try {
1475
- await facebook . validateAuthData (
1476
- { id : 'the_user_id' , token : 'the_token' } ,
1477
- { clientId : 'secret' }
1478
- ) ;
1479
- fail ( ) ;
1480
- } catch ( e ) {
1481
- expect ( e . message ) . toBe ( 'auth data is invalid for this user.' ) ;
1477
+ it_id ( 'c194d902-e697-46c9-a303-82c2d914473c' ) ( it ) (
1478
+ 'should throw error with with invalid user id (facebook.com)' ,
1479
+ async ( ) => {
1480
+ const fakeClaim = {
1481
+ iss : 'https://www.facebook.com' ,
1482
+ aud : 'invalid_client_id' ,
1483
+ sub : 'a_different_user_id' ,
1484
+ } ;
1485
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1486
+ const fakeSigningKey = { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1487
+ spyOn ( authUtils , 'getHeaderFromToken' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1488
+ spyOn ( authUtils , 'getSigningKey' ) . and . resolveTo ( fakeSigningKey ) ;
1489
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1490
+
1491
+ try {
1492
+ await facebook . validateAuthData (
1493
+ { id : 'the_user_id' , token : 'the_token' } ,
1494
+ { clientId : 'secret' }
1495
+ ) ;
1496
+ fail ( ) ;
1497
+ } catch ( e ) {
1498
+ expect ( e . message ) . toBe ( 'auth data is invalid for this user.' ) ;
1499
+ }
1482
1500
}
1483
- } ) ;
1501
+ ) ;
1484
1502
} ) ;
1485
1503
1486
1504
describe ( 'OTP TOTP auth adatper' , ( ) => {
@@ -1764,7 +1782,10 @@ describe('OTP SMS auth adatper', () => {
1764
1782
spy . calls . reset ( ) ;
1765
1783
1766
1784
await expectAsync ( Parse . User . logIn ( 'username' , 'password' ) ) . toBeRejectedWith (
1767
- new Parse . Error ( Parse . Error . OTHER_CAUSE , 'Missing additional authData mfa' )
1785
+ new Parse . Error (
1786
+ Parse . Error . OTHER_CAUSE ,
1787
+ 'Missing additional authData mfa Send request for additional auth data'
1788
+ )
1768
1789
) ;
1769
1790
const res = await request ( {
1770
1791
headers,
0 commit comments