Skip to content

Commit bd3415b

Browse files
committed
fix: use appId as clientid in upgrade
1 parent 5249f08 commit bd3415b

5 files changed

Lines changed: 16 additions & 7 deletions

File tree

schemas/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@
464464
"retryOnMissingPermissions": {
465465
"type": "boolean"
466466
},
467+
"appId": {
468+
"type": "string",
469+
"minLength": 1
470+
},
467471
"clientId": {
468472
"type": "string",
469473
"minLength": 1

src/auth/oauth/hapi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const is = require('is');
22
const { strict: assert } = require('assert');
3-
const defaults = require('lodash/defaults');
3+
const { defaults, omit } = require('lodash');
44
const { providers: Providers } = require('@hapi/bell');
55
const strategies = require('./providers');
66

@@ -83,7 +83,7 @@ module.exports = function OauthHandler(server, config) {
8383
const settings = name === 'apple' ? defaultOptions(options, server) : { provider, ...rest };
8484

8585
// init strategy
86-
server.auth.strategy(name, 'bell', settings);
86+
server.auth.strategy(name, 'bell', omit(settings, 'appId'));
8787

8888
// https://github.com/hapijs/bell/blob/master/lib/index.js#L125-L135
8989
// repeats the code from here to get another settings object and reuse it

src/auth/oauth/strategies/apple.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ async function getProfile(providerSettings, tokenResponse, query) {
9292
}
9393

9494
async function validateGrantCode(providerSettings, code, redirectUrl) {
95-
const { provider, clientId, clientSecret } = providerSettings;
95+
const { provider, appId, clientSecret } = providerSettings;
9696
const response = await httpRequest.post(provider.token, {
9797
form: {
9898
code,
99-
client_id: clientId,
100-
client_secret: clientSecret(),
99+
client_id: appId,
100+
client_secret: clientSecret(appId),
101101
grant_type: 'authorization_code',
102102
redirect_uri: redirectUrl,
103103
},
@@ -109,6 +109,7 @@ async function validateGrantCode(providerSettings, code, redirectUrl) {
109109

110110
function getProvider(options, server) {
111111
const {
112+
appId,
112113
clientId,
113114
teamId,
114115
keyId,
@@ -122,11 +123,12 @@ function getProvider(options, server) {
122123
server.ext('onRequest', fixAppleCallbackForBell);
123124

124125
return {
126+
appId,
125127
password,
126128
clientId,
127129
isSameSite,
128130
cookie,
129-
clientSecret: () => getSecretKey(teamId, clientId, keyId, privateKey),
131+
clientSecret: (cid) => getSecretKey(teamId, cid || clientId, keyId, privateKey),
130132
forceHttps: true,
131133
providerParams: {
132134
response_mode: 'form_post',

src/configs/oauth.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ exports.oauth = {
4646
},
4747
apple: {
4848
enabled: false,
49+
// used in /oauth/upgrade action as client ID
50+
// for upgrade auth code from iOS app
51+
appId: 'com.test.app',
4952
clientId: 'com.test.service', // service id from apple
5053
clientSecret: 'just-for-validation', // not used
5154
teamId: 'TEAM_ID',

test/suites/actions/oauth/upgrade.apple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const request = require('request-promise');
33
const Users = require('../../../../src');
44

55
// @TODO stub
6-
describe.skip('oauth.upgrade action', function suite() {
6+
describe('oauth.upgrade action', function suite() {
77
const service = new Users({ oauth: { providers: { apple: { enabled: true } } } });
88

99
before(() => service.connect());

0 commit comments

Comments
 (0)