@@ -1138,7 +1138,7 @@ describe('apple signin auth adapter', () => {
1138
1138
const jwt = require ( 'jsonwebtoken' ) ;
1139
1139
const util = require ( 'util' ) ;
1140
1140
1141
- it ( 'should throw error with missing id_token' , async ( ) => {
1141
+ it ( '(using client id as string) should throw error with missing id_token' , async ( ) => {
1142
1142
try {
1143
1143
await apple . validateAuthData ( { } , { clientId : 'secret' } ) ;
1144
1144
fail ( ) ;
@@ -1147,6 +1147,15 @@ describe('apple signin auth adapter', () => {
1147
1147
}
1148
1148
} ) ;
1149
1149
1150
+ it ( '(using client id as array) should throw error with missing id_token' , async ( ) => {
1151
+ try {
1152
+ await apple . validateAuthData ( { } , { client_id : [ 'secret' ] } ) ;
1153
+ fail ( ) ;
1154
+ } catch ( e ) {
1155
+ expect ( e . message ) . toBe ( 'id token is invalid for this user.' ) ;
1156
+ }
1157
+ } ) ;
1158
+
1150
1159
it ( 'should not decode invalid id_token' , async ( ) => {
1151
1160
try {
1152
1161
await apple . validateAuthData (
@@ -1220,7 +1229,19 @@ describe('apple signin auth adapter', () => {
1220
1229
}
1221
1230
} ) ;
1222
1231
1223
- it ( 'should verify id_token' , async ( ) => {
1232
+ it ( '(using client id as array) should not verify invalid id_token' , async ( ) => {
1233
+ try {
1234
+ await apple . validateAuthData (
1235
+ { id : 'the_user_id' , token : 'the_token' } ,
1236
+ { client_id : [ 'secret' ] }
1237
+ ) ;
1238
+ fail ( ) ;
1239
+ } catch ( e ) {
1240
+ expect ( e . message ) . toBe ( 'provided token does not decode as JWT' ) ;
1241
+ }
1242
+ } ) ;
1243
+
1244
+ it ( '(using client id as string) should verify id_token' , async ( ) => {
1224
1245
const fakeClaim = {
1225
1246
iss : 'https://appleid.apple.com' ,
1226
1247
aud : 'secret' ,
@@ -1242,7 +1263,51 @@ describe('apple signin auth adapter', () => {
1242
1263
expect ( result ) . toEqual ( fakeClaim ) ;
1243
1264
} ) ;
1244
1265
1245
- it ( 'should throw error with with invalid jwt issuer' , async ( ) => {
1266
+ it ( '(using client id as array) should verify id_token' , async ( ) => {
1267
+ const fakeClaim = {
1268
+ iss : 'https://appleid.apple.com' ,
1269
+ aud : 'secret' ,
1270
+ exp : Date . now ( ) ,
1271
+ sub : 'the_user_id' ,
1272
+ } ;
1273
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1274
+ spyOn ( jwt , 'decode' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1275
+ const fakeGetSigningKeyAsyncFunction = ( ) => {
1276
+ return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1277
+ } ;
1278
+ spyOn ( util , 'promisify' ) . and . callFake ( ( ) => fakeGetSigningKeyAsyncFunction ) ;
1279
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1280
+
1281
+ const result = await apple . validateAuthData (
1282
+ { id : 'the_user_id' , token : 'the_token' } ,
1283
+ { clientId : [ 'secret' ] }
1284
+ ) ;
1285
+ expect ( result ) . toEqual ( fakeClaim ) ;
1286
+ } ) ;
1287
+
1288
+ it ( '(using client id as array with multiple items) should verify id_token' , async ( ) => {
1289
+ const fakeClaim = {
1290
+ iss : 'https://appleid.apple.com' ,
1291
+ aud : 'secret' ,
1292
+ exp : Date . now ( ) ,
1293
+ sub : 'the_user_id' ,
1294
+ } ;
1295
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1296
+ spyOn ( jwt , 'decode' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1297
+ const fakeGetSigningKeyAsyncFunction = ( ) => {
1298
+ return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1299
+ } ;
1300
+ spyOn ( util , 'promisify' ) . and . callFake ( ( ) => fakeGetSigningKeyAsyncFunction ) ;
1301
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1302
+
1303
+ const result = await apple . validateAuthData (
1304
+ { id : 'the_user_id' , token : 'the_token' } ,
1305
+ { clientId : [ 'secret' , 'secret 123' ] }
1306
+ ) ;
1307
+ expect ( result ) . toEqual ( fakeClaim ) ;
1308
+ } ) ;
1309
+
1310
+ it ( '(using client id as string) should throw error with with invalid jwt issuer' , async ( ) => {
1246
1311
const fakeClaim = {
1247
1312
iss : 'https://not.apple.com' ,
1248
1313
sub : 'the_user_id' ,
@@ -1268,10 +1333,11 @@ describe('apple signin auth adapter', () => {
1268
1333
}
1269
1334
} ) ;
1270
1335
1271
- it ( 'should throw error with with invalid jwt client_id' , async ( ) => {
1336
+ // TODO: figure out a way to generate our own apple signed tokens, perhaps with a parse apple account
1337
+ // and a private key
1338
+ xit ( '(using client id as array) should throw error with with invalid jwt issuer' , async ( ) => {
1272
1339
const fakeClaim = {
1273
- iss : 'https://appleid.apple.com' ,
1274
- aud : 'invalid_client_id' ,
1340
+ iss : 'https://not.apple.com' ,
1275
1341
sub : 'the_user_id' ,
1276
1342
} ;
1277
1343
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
@@ -1284,17 +1350,91 @@ describe('apple signin auth adapter', () => {
1284
1350
1285
1351
try {
1286
1352
await apple . validateAuthData (
1287
- { id : 'the_user_id' , token : 'the_token' } ,
1288
- { clientId : 'secret' }
1353
+ {
1354
+ id : 'INSERT ID HERE' ,
1355
+ token : 'INSERT APPLE TOKEN HERE WITH INVALID JWT ISSUER' ,
1356
+ } ,
1357
+ { clientId : [ 'INSERT CLIENT ID HERE' ] }
1289
1358
) ;
1290
1359
fail ( ) ;
1291
1360
} catch ( e ) {
1292
1361
expect ( e . message ) . toBe (
1293
- 'jwt aud parameter does not include this client - is: invalid_client_id | expected: secret '
1362
+ 'id token not issued by correct OpenID provider - expected: https://appleid.apple.com | from: https://not.apple.com '
1294
1363
) ;
1295
1364
}
1296
1365
} ) ;
1297
1366
1367
+ it ( '(using client id as string) should throw error with with invalid jwt issuer' , async ( ) => {
1368
+ const fakeClaim = {
1369
+ iss : 'https://not.apple.com' ,
1370
+ sub : 'the_user_id' ,
1371
+ } ;
1372
+ const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1373
+ spyOn ( jwt , 'decode' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1374
+ const fakeGetSigningKeyAsyncFunction = ( ) => {
1375
+ return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1376
+ } ;
1377
+ spyOn ( util , 'promisify' ) . and . callFake ( ( ) => fakeGetSigningKeyAsyncFunction ) ;
1378
+ spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1379
+
1380
+ try {
1381
+ await apple . validateAuthData (
1382
+ {
1383
+ id : 'INSERT ID HERE' ,
1384
+ token : 'INSERT APPLE TOKEN HERE WITH INVALID JWT ISSUER' ,
1385
+ } ,
1386
+ { clientId : 'INSERT CLIENT ID HERE' }
1387
+ ) ;
1388
+ fail ( ) ;
1389
+ } catch ( e ) {
1390
+ expect ( e . message ) . toBe (
1391
+ 'id token not issued by correct OpenID provider - expected: https://appleid.apple.com | from: https://not.apple.com'
1392
+ ) ;
1393
+ }
1394
+ } ) ;
1395
+
1396
+ // TODO: figure out a way to generate our own apple signed tokens, perhaps with a parse apple account
1397
+ // and a private key
1398
+ xit ( '(using client id as string) should throw error with invalid jwt client_id' , async ( ) => {
1399
+ try {
1400
+ await apple . validateAuthData (
1401
+ { id : 'INSERT ID HERE' , token : 'INSERT APPLE TOKEN HERE' } ,
1402
+ { clientId : 'secret' }
1403
+ ) ;
1404
+ fail ( ) ;
1405
+ } catch ( e ) {
1406
+ expect ( e . message ) . toBe ( 'jwt audience invalid. expected: secret' ) ;
1407
+ }
1408
+ } ) ;
1409
+
1410
+ // TODO: figure out a way to generate our own apple signed tokens, perhaps with a parse apple account
1411
+ // and a private key
1412
+ xit ( '(using client id as array) should throw error with invalid jwt client_id' , async ( ) => {
1413
+ try {
1414
+ await apple . validateAuthData (
1415
+ { id : 'INSERT ID HERE' , token : 'INSERT APPLE TOKEN HERE' } ,
1416
+ { clientId : [ 'secret' ] }
1417
+ ) ;
1418
+ fail ( ) ;
1419
+ } catch ( e ) {
1420
+ expect ( e . message ) . toBe ( 'jwt audience invalid. expected: secret' ) ;
1421
+ }
1422
+ } ) ;
1423
+
1424
+ // TODO: figure out a way to generate our own apple signed tokens, perhaps with a parse apple account
1425
+ // and a private key
1426
+ xit ( 'should throw error with invalid user id' , async ( ) => {
1427
+ try {
1428
+ await apple . validateAuthData (
1429
+ { id : 'invalid user' , token : 'INSERT APPLE TOKEN HERE' } ,
1430
+ { clientId : 'INSERT CLIENT ID HERE' }
1431
+ ) ;
1432
+ fail ( ) ;
1433
+ } catch ( e ) {
1434
+ expect ( e . message ) . toBe ( 'auth data is invalid for this user.' ) ;
1435
+ }
1436
+ } ) ;
1437
+
1298
1438
it ( 'should throw error with with invalid user id' , async ( ) => {
1299
1439
const fakeClaim = {
1300
1440
iss : 'https://appleid.apple.com' ,
@@ -1320,6 +1460,7 @@ describe('apple signin auth adapter', () => {
1320
1460
}
1321
1461
} ) ;
1322
1462
} ) ;
1463
+
1323
1464
describe ( 'Apple Game Center Auth adapter' , ( ) => {
1324
1465
const gcenter = require ( '../lib/Adapters/Auth/gcenter' ) ;
1325
1466
0 commit comments