|
1 | 1 | const { strict: assert } = require('assert'); |
2 | | -const Boom = require('@hapi/boom'); |
3 | 2 |
|
4 | 3 | const { ActionTransport } = require('@microfleet/plugin-router'); |
5 | 4 |
|
6 | 5 | const { oauthVerification, mserviceVerification } = require('../../auth/oauth'); |
7 | 6 | const formOAuthResponse = require('../../auth/oauth/utils/form-oauth-response'); |
8 | | -const { validateGrantCode } = require('../../auth/oauth/strategies/apple'); |
| 7 | +const { upgradeAppleCode } = require('../../auth/oauth/strategies/apple'); |
9 | 8 |
|
10 | 9 | /** |
11 | 10 | * @api {amqp} <prefix>.oauth.upgrade Upgardes existing SSO token to service-verified token |
@@ -38,22 +37,14 @@ async function upgrade(request) { |
38 | 37 | query.jwt = params.jwt; |
39 | 38 | } |
40 | 39 |
|
41 | | - let credentials; |
42 | | - |
43 | | - if (provider === 'apple') { |
44 | | - try { |
45 | | - const redirectUrl = transportRequest.url.href |
46 | | - .replace(/\/upgrade$/, '/apple') |
47 | | - .replace(/^http:\/\//, 'https://'); |
48 | | - const tokenResponse = await validateGrantCode(providerSettings, token, redirectUrl); |
49 | | - credentials = await profile.call(providerSettings, { token, query }, tokenResponse); |
50 | | - } catch (error) { |
51 | | - throw Boom.internal(error); |
52 | | - } |
53 | | - } else { |
54 | | - // verifies token by retreiving profile |
55 | | - credentials = await profile.call(providerSettings, { token, query }); |
56 | | - } |
| 40 | + const credentials = provider === 'apple' |
| 41 | + ? await upgradeAppleCode({ |
| 42 | + query, |
| 43 | + providerSettings, |
| 44 | + code: token, |
| 45 | + redirectUrl: transportRequest.url.href.replace(/\/upgrade$/, '/apple').replace(/^http:\/\//, 'https://'), |
| 46 | + }) |
| 47 | + : await profile.call(providerSettings, { token, query }); |
57 | 48 |
|
58 | 49 | // ensure its a shallow copy as we will mutate it later |
59 | 50 | const oauthConfig = { ...this.config.oauth.providers[provider] }; |
|
0 commit comments