@@ -596,6 +596,7 @@ describe('instagram auth adapter', () => {
596
596
describe ( 'google auth adapter' , ( ) => {
597
597
const google = require ( '../lib/Adapters/Auth/google' ) ;
598
598
const jwt = require ( 'jsonwebtoken' ) ;
599
+ const authUtils = require ( '../lib/Adapters/Auth/utils' ) ;
599
600
600
601
it ( 'should throw error with missing id_token' , async ( ) => {
601
602
try {
@@ -618,7 +619,7 @@ describe('google auth adapter', () => {
618
619
// it('should throw error if public key used to encode token is not available', async () => {
619
620
// const fakeDecodedToken = { header: { kid: '789', alg: 'RS256' } };
620
621
// try {
621
- // spyOn(jwt , 'decode ').and.callFake(() => fakeDecodedToken);
622
+ // spyOn(authUtils , 'getHeaderFromToken ').and.callFake(() => fakeDecodedToken);
622
623
623
624
// await google.validateAuthData({ id: 'the_user_id', id_token: 'the_token' }, {});
624
625
// fail();
@@ -637,7 +638,7 @@ describe('google auth adapter', () => {
637
638
sub : 'the_user_id' ,
638
639
} ;
639
640
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
640
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
641
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
641
642
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
642
643
643
644
const result = await google . validateAuthData (
@@ -653,7 +654,7 @@ describe('google auth adapter', () => {
653
654
sub : 'the_user_id' ,
654
655
} ;
655
656
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
656
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
657
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
657
658
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
658
659
659
660
try {
@@ -677,7 +678,7 @@ describe('google auth adapter', () => {
677
678
sub : 'the_user_id' ,
678
679
} ;
679
680
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
680
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
681
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
681
682
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
682
683
683
684
try {
@@ -699,7 +700,7 @@ describe('google auth adapter', () => {
699
700
sub : 'the_user_id' ,
700
701
} ;
701
702
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
702
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
703
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
703
704
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
704
705
705
706
try {
@@ -1402,6 +1403,7 @@ describe('apple signin auth adapter', () => {
1402
1403
const apple = require ( '../lib/Adapters/Auth/apple' ) ;
1403
1404
const jwt = require ( 'jsonwebtoken' ) ;
1404
1405
const util = require ( 'util' ) ;
1406
+ const authUtils = require ( '../lib/Adapters/Auth/utils' ) ;
1405
1407
1406
1408
it ( '(using client id as string) should throw error with missing id_token' , async ( ) => {
1407
1409
try {
@@ -1436,7 +1438,7 @@ describe('apple signin auth adapter', () => {
1436
1438
it ( 'should throw error if public key used to encode token is not available' , async ( ) => {
1437
1439
const fakeDecodedToken = { header : { kid : '789' , alg : 'RS256' } } ;
1438
1440
try {
1439
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1441
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
1440
1442
1441
1443
await apple . validateAuthData (
1442
1444
{ id : 'the_user_id' , token : 'the_token' } ,
@@ -1458,7 +1460,7 @@ describe('apple signin auth adapter', () => {
1458
1460
sub : 'the_user_id' ,
1459
1461
} ;
1460
1462
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1461
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1463
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
1462
1464
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
1463
1465
const fakeGetSigningKeyAsyncFunction = ( ) => {
1464
1466
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
@@ -1475,7 +1477,7 @@ describe('apple signin auth adapter', () => {
1475
1477
1476
1478
it ( 'should not verify invalid id_token' , async ( ) => {
1477
1479
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1478
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1480
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1479
1481
const fakeGetSigningKeyAsyncFunction = ( ) => {
1480
1482
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1481
1483
} ;
@@ -1512,7 +1514,7 @@ describe('apple signin auth adapter', () => {
1512
1514
sub : 'the_user_id' ,
1513
1515
} ;
1514
1516
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1515
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1517
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1516
1518
const fakeGetSigningKeyAsyncFunction = ( ) => {
1517
1519
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1518
1520
} ;
@@ -1534,7 +1536,7 @@ describe('apple signin auth adapter', () => {
1534
1536
sub : 'the_user_id' ,
1535
1537
} ;
1536
1538
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1537
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1539
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1538
1540
const fakeGetSigningKeyAsyncFunction = ( ) => {
1539
1541
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1540
1542
} ;
@@ -1556,7 +1558,7 @@ describe('apple signin auth adapter', () => {
1556
1558
sub : 'the_user_id' ,
1557
1559
} ;
1558
1560
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1559
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1561
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1560
1562
const fakeGetSigningKeyAsyncFunction = ( ) => {
1561
1563
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1562
1564
} ;
@@ -1576,7 +1578,7 @@ describe('apple signin auth adapter', () => {
1576
1578
sub : 'the_user_id' ,
1577
1579
} ;
1578
1580
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1579
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1581
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1580
1582
const fakeGetSigningKeyAsyncFunction = ( ) => {
1581
1583
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1582
1584
} ;
@@ -1604,7 +1606,7 @@ describe('apple signin auth adapter', () => {
1604
1606
sub : 'the_user_id' ,
1605
1607
} ;
1606
1608
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1607
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1609
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1608
1610
const fakeGetSigningKeyAsyncFunction = ( ) => {
1609
1611
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1610
1612
} ;
@@ -1633,7 +1635,7 @@ describe('apple signin auth adapter', () => {
1633
1635
sub : 'the_user_id' ,
1634
1636
} ;
1635
1637
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1636
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1638
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1637
1639
const fakeGetSigningKeyAsyncFunction = ( ) => {
1638
1640
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1639
1641
} ;
@@ -1705,7 +1707,7 @@ describe('apple signin auth adapter', () => {
1705
1707
sub : 'a_different_user_id' ,
1706
1708
} ;
1707
1709
const fakeDecodedToken = { header : { kid : '123' , alg : 'RS256' } } ;
1708
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1710
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
1709
1711
const fakeGetSigningKeyAsyncFunction = ( ) => {
1710
1712
return { kid : '123' , rsaPublicKey : 'the_rsa_public_key' } ;
1711
1713
} ;
@@ -1972,6 +1974,7 @@ describe('facebook limited auth adapter', () => {
1972
1974
const facebook = require ( '../lib/Adapters/Auth/facebook' ) ;
1973
1975
const jwt = require ( 'jsonwebtoken' ) ;
1974
1976
const util = require ( 'util' ) ;
1977
+ const authUtils = require ( '../lib/Adapters/Auth/utils' ) ;
1975
1978
1976
1979
// TODO: figure out a way to run this test alongside facebook classic tests
1977
1980
xit ( '(using client id as string) should throw error with missing id_token' , async ( ) => {
@@ -2010,7 +2013,7 @@ describe('facebook limited auth adapter', () => {
2010
2013
header : { kid : '789' , alg : 'RS256' } ,
2011
2014
} ;
2012
2015
try {
2013
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2016
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
2014
2017
2015
2018
await facebook . validateAuthData (
2016
2019
{ id : 'the_user_id' , token : 'the_token' } ,
@@ -2034,7 +2037,7 @@ describe('facebook limited auth adapter', () => {
2034
2037
const fakeDecodedToken = {
2035
2038
header : { kid : '123' , alg : 'RS256' } ,
2036
2039
} ;
2037
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2040
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken . header ) ;
2038
2041
spyOn ( jwt , 'verify' ) . and . callFake ( ( ) => fakeClaim ) ;
2039
2042
const fakeGetSigningKeyAsyncFunction = ( ) => {
2040
2043
return {
@@ -2056,7 +2059,7 @@ describe('facebook limited auth adapter', () => {
2056
2059
const fakeDecodedToken = {
2057
2060
header : { kid : '123' , alg : 'RS256' } ,
2058
2061
} ;
2059
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2062
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2060
2063
const fakeGetSigningKeyAsyncFunction = ( ) => {
2061
2064
return {
2062
2065
kid : '123' ,
@@ -2098,7 +2101,7 @@ describe('facebook limited auth adapter', () => {
2098
2101
const fakeDecodedToken = {
2099
2102
header : { kid : '123' , alg : 'RS256' } ,
2100
2103
} ;
2101
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2104
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2102
2105
const fakeGetSigningKeyAsyncFunction = ( ) => {
2103
2106
return {
2104
2107
kid : '123' ,
@@ -2125,7 +2128,7 @@ describe('facebook limited auth adapter', () => {
2125
2128
const fakeDecodedToken = {
2126
2129
header : { kid : '123' , alg : 'RS256' } ,
2127
2130
} ;
2128
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2131
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2129
2132
const fakeGetSigningKeyAsyncFunction = ( ) => {
2130
2133
return {
2131
2134
kid : '123' ,
@@ -2152,7 +2155,7 @@ describe('facebook limited auth adapter', () => {
2152
2155
const fakeDecodedToken = {
2153
2156
header : { kid : '123' , alg : 'RS256' } ,
2154
2157
} ;
2155
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2158
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2156
2159
const fakeGetSigningKeyAsyncFunction = ( ) => {
2157
2160
return {
2158
2161
kid : '123' ,
@@ -2177,7 +2180,7 @@ describe('facebook limited auth adapter', () => {
2177
2180
const fakeDecodedToken = {
2178
2181
header : { kid : '123' , alg : 'RS256' } ,
2179
2182
} ;
2180
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2183
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2181
2184
const fakeGetSigningKeyAsyncFunction = ( ) => {
2182
2185
return {
2183
2186
kid : '123' ,
@@ -2210,7 +2213,7 @@ describe('facebook limited auth adapter', () => {
2210
2213
const fakeDecodedToken = {
2211
2214
header : { kid : '123' , alg : 'RS256' } ,
2212
2215
} ;
2213
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2216
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2214
2217
const fakeGetSigningKeyAsyncFunction = ( ) => {
2215
2218
return {
2216
2219
kid : '123' ,
@@ -2244,7 +2247,7 @@ describe('facebook limited auth adapter', () => {
2244
2247
const fakeDecodedToken = {
2245
2248
header : { kid : '123' , alg : 'RS256' } ,
2246
2249
} ;
2247
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2250
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2248
2251
const fakeGetSigningKeyAsyncFunction = ( ) => {
2249
2252
return {
2250
2253
kid : '123' ,
@@ -2330,7 +2333,7 @@ describe('facebook limited auth adapter', () => {
2330
2333
const fakeDecodedToken = {
2331
2334
header : { kid : '123' , alg : 'RS256' } ,
2332
2335
} ;
2333
- spyOn ( jwt , 'decode ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2336
+ spyOn ( authUtils , 'getHeaderFromToken ' ) . and . callFake ( ( ) => fakeDecodedToken ) ;
2334
2337
const fakeGetSigningKeyAsyncFunction = ( ) => {
2335
2338
return {
2336
2339
kid : '123' ,
0 commit comments