Skip to content

Commit 05774c5

Browse files
authored
Fix: Linking with Apple Auth (parse-community#5755)
Rename from apple-signin to apple (key names can't have hyphens Rename id_token to id (auth adapters require id)
1 parent 6358ccc commit 05774c5

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

spec/AuthenticationAdapters.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const responses = {
1717

1818
describe('AuthenticationProviders', function() {
1919
[
20-
'apple-signin',
20+
'apple',
2121
'facebook',
2222
'facebookaccountkit',
2323
'github',
@@ -51,7 +51,7 @@ describe('AuthenticationProviders', function() {
5151
});
5252

5353
it(`should provide the right responses for adapter ${providerName}`, async () => {
54-
if (providerName === 'twitter' || providerName === 'apple-signin') {
54+
if (providerName === 'twitter' || providerName === 'apple') {
5555
return;
5656
}
5757
spyOn(require('../lib/Adapters/Auth/httpsRequest'), 'get').and.callFake(
@@ -1087,22 +1087,22 @@ describe('oauth2 auth adapter', () => {
10871087
});
10881088

10891089
describe('apple signin auth adapter', () => {
1090-
const apple = require('../lib/Adapters/Auth/apple-signin');
1090+
const apple = require('../lib/Adapters/Auth/apple');
10911091
const jwt = require('jsonwebtoken');
10921092

10931093
it('should throw error with missing id_token', async () => {
10941094
try {
10951095
await apple.validateAuthData({}, { client_id: 'secret' });
10961096
fail();
10971097
} catch (e) {
1098-
expect(e.message).toBe('id_token is invalid for this user.');
1098+
expect(e.message).toBe('id token is invalid for this user.');
10991099
}
11001100
});
11011101

11021102
it('should not verify invalid id_token', async () => {
11031103
try {
11041104
await apple.validateAuthData(
1105-
{ id_token: 'the_token' },
1105+
{ id: 'the_token' },
11061106
{ client_id: 'secret' }
11071107
);
11081108
fail();
@@ -1120,7 +1120,7 @@ describe('apple signin auth adapter', () => {
11201120
spyOn(jwt, 'verify').and.callFake(() => fakeClaim);
11211121

11221122
const result = await apple.validateAuthData(
1123-
{ id_token: 'the_token' },
1123+
{ id: 'the_token' },
11241124
{ client_id: 'secret' }
11251125
);
11261126
expect(result).toEqual(fakeClaim);
@@ -1134,13 +1134,13 @@ describe('apple signin auth adapter', () => {
11341134

11351135
try {
11361136
await apple.validateAuthData(
1137-
{ id_token: 'the_token' },
1137+
{ id: 'the_token' },
11381138
{ client_id: 'secret' }
11391139
);
11401140
fail();
11411141
} catch (e) {
11421142
expect(e.message).toBe(
1143-
'id_token not issued by correct OpenID provider - expected: https://appleid.apple.com | from: https://not.apple.com'
1143+
'id token not issued by correct OpenID provider - expected: https://appleid.apple.com | from: https://not.apple.com'
11441144
);
11451145
}
11461146
});
@@ -1154,7 +1154,7 @@ describe('apple signin auth adapter', () => {
11541154

11551155
try {
11561156
await apple.validateAuthData(
1157-
{ id_token: 'the_token' },
1157+
{ id: 'the_token' },
11581158
{ client_id: 'secret' }
11591159
);
11601160
fail();

src/Adapters/Auth/apple-signin.js renamed to src/Adapters/Auth/apple.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const verifyIdToken = async (token, clientID) => {
2121
if (!token) {
2222
throw new Parse.Error(
2323
Parse.Error.OBJECT_NOT_FOUND,
24-
'id_token is invalid for this user.'
24+
'id token is invalid for this user.'
2525
);
2626
}
2727
const applePublicKey = await getApplePublicKey();
@@ -30,7 +30,7 @@ const verifyIdToken = async (token, clientID) => {
3030
if (jwtClaims.iss !== TOKEN_ISSUER) {
3131
throw new Parse.Error(
3232
Parse.Error.OBJECT_NOT_FOUND,
33-
`id_token not issued by correct OpenID provider - expected: ${TOKEN_ISSUER} | from: ${jwtClaims.iss}`
33+
`id token not issued by correct OpenID provider - expected: ${TOKEN_ISSUER} | from: ${jwtClaims.iss}`
3434
);
3535
}
3636
if (clientID !== undefined && jwtClaims.aud !== clientID) {
@@ -42,9 +42,9 @@ const verifyIdToken = async (token, clientID) => {
4242
return jwtClaims;
4343
};
4444

45-
// Returns a promise that fulfills if this id_token is valid
45+
// Returns a promise that fulfills if this id token is valid
4646
function validateAuthData(authData, options = {}) {
47-
return verifyIdToken(authData.id_token, options.client_id);
47+
return verifyIdToken(authData.id, options.client_id);
4848
}
4949

5050
// Returns a promise that fulfills if this app id is valid.
@@ -53,6 +53,6 @@ function validateAppId() {
5353
}
5454

5555
module.exports = {
56-
validateAppId: validateAppId,
57-
validateAuthData: validateAuthData,
56+
validateAppId,
57+
validateAuthData,
5858
};

src/Adapters/Auth/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import loadAdapter from '../AdapterLoader';
22

3+
const apple = require('./apple');
34
const facebook = require('./facebook');
45
const facebookaccountkit = require('./facebookaccountkit');
56
const instagram = require('./instagram');
@@ -28,6 +29,7 @@ const anonymous = {
2829
};
2930

3031
const providers = {
32+
apple,
3133
facebook,
3234
facebookaccountkit,
3335
instagram,

0 commit comments

Comments
 (0)