@unchainedshop/plugins 2.14.2 → 3.0.0-alpha3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delivery/pick-mup.js +1 -1
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +1 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js.map +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +3 -3
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/index.js +1 -1
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +2 -2
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/paypal-checkout.js +7 -1
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/index.js +0 -1
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/api/api/SaferpayClient.d.ts +1 -1
- package/lib/payment/saferpay/api/api/SaferpayClient.d.ts.map +1 -1
- package/lib/payment/saferpay/db/SaferpayTransactionsCollection.d.ts +1 -1
- package/lib/payment/saferpay/db/SaferpayTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.d.ts +3 -3
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +1 -1
- package/lib/plugins-index.d.ts +2 -33
- package/lib/plugins-index.d.ts.map +1 -1
- package/lib/plugins-index.js +16 -71
- package/lib/plugins-index.js.map +1 -1
- package/lib/presets/base-express.d.ts +3 -0
- package/lib/presets/base-express.d.ts.map +1 -0
- package/lib/presets/base-express.js +6 -0
- package/lib/presets/base-express.js.map +1 -0
- package/lib/presets/base-modules.d.ts +29 -0
- package/lib/presets/base-modules.d.ts.map +1 -0
- package/lib/presets/base-modules.js +40 -0
- package/lib/presets/base-modules.js.map +1 -0
- package/lib/presets/countries/ch.d.ts +4 -0
- package/lib/presets/countries/ch.d.ts.map +1 -0
- package/lib/presets/countries/ch.js +4 -0
- package/lib/presets/countries/ch.js.map +1 -0
- package/lib/presets/crypto-express.d.ts +4 -0
- package/lib/presets/crypto-express.d.ts.map +1 -0
- package/lib/presets/crypto-express.js +9 -0
- package/lib/presets/crypto-express.js.map +1 -0
- package/lib/presets/crypto-modules.d.ts +11 -0
- package/lib/presets/crypto-modules.d.ts.map +1 -0
- package/lib/presets/crypto-modules.js +14 -0
- package/lib/presets/crypto-modules.js.map +1 -0
- package/lib/pricing/delivery-swiss-tax.d.ts +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +1 -1
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/discount-100-off.d.ts +1 -1
- package/lib/pricing/discount-100-off.d.ts.map +1 -1
- package/lib/pricing/discount-half-price-manual.d.ts +1 -1
- package/lib/pricing/discount-half-price-manual.d.ts.map +1 -1
- package/lib/pricing/discount-half-price.d.ts +1 -1
- package/lib/pricing/discount-half-price.d.ts.map +1 -1
- package/lib/pricing/free-delivery.d.ts +1 -1
- package/lib/pricing/free-delivery.d.ts.map +1 -1
- package/lib/pricing/free-delivery.js +1 -1
- package/lib/pricing/free-delivery.js.map +1 -1
- package/lib/pricing/free-payment.d.ts +1 -1
- package/lib/pricing/free-payment.d.ts.map +1 -1
- package/lib/pricing/free-payment.js +1 -1
- package/lib/pricing/free-payment.js.map +1 -1
- package/lib/pricing/order-delivery.d.ts +1 -1
- package/lib/pricing/order-delivery.d.ts.map +1 -1
- package/lib/pricing/order-discount.d.ts +1 -1
- package/lib/pricing/order-discount.d.ts.map +1 -1
- package/lib/pricing/order-discount.js +1 -1
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +1 -1
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +2 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +17 -4
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-discount.js +1 -1
- package/lib/pricing/product-discount.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.d.ts +1 -1
- package/lib/pricing/product-price-rateconversion.d.ts.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +1 -1
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +4 -12
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +3 -3
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +4 -3
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/bulk-import.d.ts +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +1 -0
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +1 -1
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/error-notifications.js +1 -1
- package/lib/worker/error-notifications.js.map +1 -1
- package/lib/worker/export-token.d.ts +2 -2
- package/lib/worker/export-token.d.ts.map +1 -1
- package/lib/worker/export-token.js +1 -1
- package/lib/worker/export-token.js.map +1 -1
- package/lib/worker/external.d.ts +1 -1
- package/lib/worker/external.d.ts.map +1 -1
- package/lib/worker/http-request.d.ts +1 -1
- package/lib/worker/http-request.d.ts.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/update-ecb-rates.js +2 -2
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/lib/worker/update-token-ownership.d.ts +1 -1
- package/lib/worker/update-token-ownership.d.ts.map +1 -1
- package/lib/worker/zombie-killer.d.ts +1 -1
- package/lib/worker/zombie-killer.d.ts.map +1 -1
- package/package.json +23 -21
- package/src/delivery/pick-mup.ts +1 -1
- package/src/delivery/post.ts +1 -1
- package/src/delivery/send-message.ts +1 -1
- package/src/delivery/stores.ts +1 -1
- package/src/enrollments/licensed.ts +1 -1
- package/src/files/gridfs/gridfs-adapter.ts +1 -1
- package/src/files/gridfs/gridfs-webhook.ts +1 -1
- package/src/files/minio/minio-adapter.ts +1 -1
- package/src/filters/local-search.ts +4 -4
- package/src/filters/strict-equal.ts +1 -1
- package/src/payment/apple-iap/adapter.ts +3 -3
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
- package/src/payment/braintree.ts +1 -1
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
- package/src/payment/cryptopay/middleware.ts +3 -3
- package/src/payment/cryptopay/plugin.ts +5 -5
- package/src/payment/datatrans-v2/index.ts +2 -2
- package/src/payment/datatrans-v2/middleware.ts +1 -1
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +2 -2
- package/src/payment/invoice-prepaid.ts +1 -1
- package/src/payment/invoice.ts +1 -1
- package/src/payment/paypal-checkout.ts +8 -2
- package/src/payment/payrexx/index.ts +1 -2
- package/src/payment/payrexx/middleware.ts +1 -1
- package/src/payment/postfinance-checkout/index.ts +1 -1
- package/src/payment/postfinance-checkout/middleware.ts +1 -1
- package/src/payment/postfinance-checkout/utils.ts +1 -1
- package/src/payment/saferpay/adapter.ts +2 -2
- package/src/payment/saferpay/api/api/SaferpayClient.ts +1 -1
- package/src/payment/saferpay/db/SaferpayTransactionsCollection.ts +1 -1
- package/src/payment/saferpay/middleware.ts +1 -1
- package/src/payment/stripe/index.ts +1 -1
- package/src/payment/stripe/middleware.ts +1 -1
- package/src/payment/stripe/stripe.ts +4 -4
- package/src/plugins-index.ts +18 -101
- package/src/presets/base-express.ts +7 -0
- package/src/presets/base-modules.ts +56 -0
- package/src/presets/countries/ch.ts +3 -0
- package/src/presets/crypto-express.ts +12 -0
- package/src/presets/crypto-modules.ts +23 -0
- package/src/pricing/delivery-swiss-tax.ts +3 -6
- package/src/pricing/discount-100-off.ts +1 -1
- package/src/pricing/discount-half-price-manual.ts +1 -1
- package/src/pricing/discount-half-price.ts +1 -1
- package/src/pricing/free-delivery.ts +5 -2
- package/src/pricing/free-payment.ts +5 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +1 -1
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +1 -1
- package/src/pricing/product-catalog-price.ts +24 -7
- package/src/pricing/product-discount.ts +2 -5
- package/src/pricing/product-price-rateconversion.ts +3 -2
- package/src/pricing/product-round.ts +1 -1
- package/src/pricing/product-swiss-tax.test.ts +1 -0
- package/src/pricing/product-swiss-tax.ts +11 -8
- package/src/quotations/manual.ts +1 -1
- package/src/warehousing/eth-minter.ts +8 -6
- package/src/warehousing/store.ts +1 -1
- package/src/worker/bulk-import.ts +2 -2
- package/src/worker/email.ts +1 -1
- package/src/worker/enrollment-order-generator.ts +8 -6
- package/src/worker/error-notifications.ts +1 -1
- package/src/worker/export-token.ts +8 -3
- package/src/worker/external.ts +1 -1
- package/src/worker/heartbeat.ts +1 -1
- package/src/worker/http-request.ts +1 -1
- package/src/worker/message.ts +1 -2
- package/src/worker/push-notification.ts +1 -1
- package/src/worker/sms.ts +1 -1
- package/src/worker/update-coinbase-rates.ts +2 -2
- package/src/worker/update-ecb-rates.ts +4 -4
- package/src/worker/update-token-ownership.ts +1 -1
- package/src/worker/zombie-killer.ts +1 -1
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/src/accounts/google-oauth.ts +0 -181
- package/src/accounts/linkedin-oauth.ts +0 -103
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { OAuth2Director, OAuth2Adapter } from '@unchainedshop/core-accountsjs';
|
|
2
|
-
const { LINKED_IN_OAUTH_CLIENT_ID, LINKED_IN_OAUTH_CLIENT_SECRET } = process.env;
|
|
3
|
-
const getLinkedInAuthorizationCode = async ({ code, redirectUri, clientId, clientSecret, }) => {
|
|
4
|
-
const response = await fetch('https://www.linkedin.com/oauth/v2/accessToken', {
|
|
5
|
-
method: 'POST',
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
duplex: 'half',
|
|
9
|
-
headers: {
|
|
10
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
11
|
-
},
|
|
12
|
-
body: new URLSearchParams({
|
|
13
|
-
code,
|
|
14
|
-
client_id: clientId,
|
|
15
|
-
grant_type: 'authorization_code',
|
|
16
|
-
client_secret: clientSecret,
|
|
17
|
-
redirect_uri: redirectUri,
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
return response.json();
|
|
21
|
-
};
|
|
22
|
-
const normalizeProfileData = (data) => {
|
|
23
|
-
const { name, given_name, family_name, email, email_verified, picture, sub } = data;
|
|
24
|
-
return {
|
|
25
|
-
id: sub,
|
|
26
|
-
displayName: name,
|
|
27
|
-
firstName: given_name,
|
|
28
|
-
lastName: family_name,
|
|
29
|
-
email: email_verified ? email : undefined,
|
|
30
|
-
avatarUrl: picture,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const LinkedInOAuthAdapter = {
|
|
34
|
-
...OAuth2Adapter,
|
|
35
|
-
key: 'linked-in-oauth2',
|
|
36
|
-
label: 'LinkedIn Oauth',
|
|
37
|
-
version: '1',
|
|
38
|
-
provider: 'linkedin',
|
|
39
|
-
config: {
|
|
40
|
-
clientId: LINKED_IN_OAUTH_CLIENT_ID,
|
|
41
|
-
scopes: ['r_liteprofile', 'r_emailaddress', 'email', 'openid', 'profile'],
|
|
42
|
-
},
|
|
43
|
-
actions: () => {
|
|
44
|
-
return {
|
|
45
|
-
...OAuth2Adapter.actions(null),
|
|
46
|
-
configurationError: () => {
|
|
47
|
-
return '';
|
|
48
|
-
},
|
|
49
|
-
isActive: () => {
|
|
50
|
-
return Boolean(LINKED_IN_OAUTH_CLIENT_ID && LINKED_IN_OAUTH_CLIENT_SECRET);
|
|
51
|
-
},
|
|
52
|
-
getAuthorizationToken: async (authorizationCode, redirectUrl) => {
|
|
53
|
-
return getLinkedInAuthorizationCode({
|
|
54
|
-
code: authorizationCode,
|
|
55
|
-
clientId: LinkedInOAuthAdapter.config.clientId,
|
|
56
|
-
redirectUri: redirectUrl,
|
|
57
|
-
clientSecret: LINKED_IN_OAUTH_CLIENT_SECRET,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
getAccountData: async ({ access_token }) => {
|
|
61
|
-
const response = await fetch('https://api.linkedin.com/v2/userinfo', {
|
|
62
|
-
headers: {
|
|
63
|
-
Authorization: `Bearer ${access_token}`,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
const profileInfoJSON = await response.json();
|
|
67
|
-
return normalizeProfileData(profileInfoJSON);
|
|
68
|
-
},
|
|
69
|
-
isTokenValid: async ({ access_token }) => {
|
|
70
|
-
const response = await fetch(`https://api.linkedin.com/oauth/v2/accessTokenValidation?q=full&access_token=${access_token}`);
|
|
71
|
-
const tokenInfo = await response.json();
|
|
72
|
-
if (tokenInfo.error) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
OAuth2Director.registerAdapter(LinkedInOAuthAdapter);
|
|
81
|
-
export default LinkedInOAuthAdapter;
|
|
82
|
-
//# sourceMappingURL=linkedin-oauth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"linkedin-oauth.js","sourceRoot":"","sources":["../../src/accounts/linkedin-oauth.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import { IOAuth2Adapter } from '@unchainedshop/types/accounts.js';
|
|
3
|
-
import { OAuth2Director, OAuth2Adapter } from '@unchainedshop/core-accountsjs';
|
|
4
|
-
|
|
5
|
-
const { GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET } = process.env;
|
|
6
|
-
|
|
7
|
-
const getGoggleAuthorizationCode = async ({
|
|
8
|
-
code,
|
|
9
|
-
redirectUri,
|
|
10
|
-
clientId,
|
|
11
|
-
clientSecret,
|
|
12
|
-
}): Promise<any> => {
|
|
13
|
-
const response = await fetch('https://oauth2.googleapis.com/token', {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
},
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
duplex: 'half',
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
code,
|
|
23
|
-
client_id: clientId,
|
|
24
|
-
grant_type: 'authorization_code',
|
|
25
|
-
client_secret: clientSecret,
|
|
26
|
-
redirect_uri: redirectUri,
|
|
27
|
-
access_type: 'offline',
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return response.json();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const normalizeProfileData = (data) => {
|
|
35
|
-
const {
|
|
36
|
-
names = [],
|
|
37
|
-
genders = [],
|
|
38
|
-
addresses = [],
|
|
39
|
-
emailAddresses = [],
|
|
40
|
-
phoneNumbers = [],
|
|
41
|
-
birthdays = [],
|
|
42
|
-
photos = [],
|
|
43
|
-
} = data;
|
|
44
|
-
const [name] = names;
|
|
45
|
-
const [gender] = genders;
|
|
46
|
-
const [email] = emailAddresses;
|
|
47
|
-
const [birthday] = birthdays;
|
|
48
|
-
const [phone] = phoneNumbers;
|
|
49
|
-
const [address] = addresses;
|
|
50
|
-
const [photo] = photos;
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
id: data.sub,
|
|
54
|
-
firstName: name?.givenName,
|
|
55
|
-
lastName: name?.familyName,
|
|
56
|
-
displayName: name?.displayName,
|
|
57
|
-
gender: gender?.value,
|
|
58
|
-
email: email?.value,
|
|
59
|
-
birthDate: birthday?.date
|
|
60
|
-
? new Date(birthday?.date?.year ?? 0, birthdays?.date?.month ?? 0, birthday?.date?.day ?? 0)
|
|
61
|
-
: undefined,
|
|
62
|
-
phoneNumber: phone?.canonicalForm,
|
|
63
|
-
address: address?.formattedValue,
|
|
64
|
-
avatarUrl: photo?.url,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const parseGoogleIdToken = (idToken: string) => {
|
|
69
|
-
const [, base64UserInfo] = idToken.split('.');
|
|
70
|
-
const buff = Buffer.from(base64UserInfo, 'base64');
|
|
71
|
-
const data = JSON.parse(buff.toString());
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
id: data.sub,
|
|
75
|
-
email: data?.email,
|
|
76
|
-
firstName: data?.given_name,
|
|
77
|
-
lastName: data?.family_name,
|
|
78
|
-
avatarUrl: data?.picture,
|
|
79
|
-
fullName: data?.name,
|
|
80
|
-
exp: data?.exp,
|
|
81
|
-
...data,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const GoogleOAuth2Adapter: IOAuth2Adapter = {
|
|
86
|
-
...OAuth2Adapter,
|
|
87
|
-
key: 'google-oauth2',
|
|
88
|
-
label: 'Google Oauth',
|
|
89
|
-
version: '1',
|
|
90
|
-
provider: 'google',
|
|
91
|
-
config: {
|
|
92
|
-
clientId: GOOGLE_OAUTH_CLIENT_ID,
|
|
93
|
-
scopes: [
|
|
94
|
-
'genders',
|
|
95
|
-
'emailAddresses',
|
|
96
|
-
'phoneNumbers',
|
|
97
|
-
'addresses',
|
|
98
|
-
'birthdays',
|
|
99
|
-
'metadata',
|
|
100
|
-
'names',
|
|
101
|
-
'photos',
|
|
102
|
-
'locations',
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
actions: () => {
|
|
107
|
-
return {
|
|
108
|
-
...OAuth2Adapter.actions(null),
|
|
109
|
-
configurationError: () => {
|
|
110
|
-
return '';
|
|
111
|
-
},
|
|
112
|
-
isActive: () => {
|
|
113
|
-
return Boolean(GOOGLE_OAUTH_CLIENT_ID && GOOGLE_OAUTH_CLIENT_SECRET);
|
|
114
|
-
},
|
|
115
|
-
getAuthorizationToken: async (authorizationCode, redirectUrl) => {
|
|
116
|
-
return getGoggleAuthorizationCode({
|
|
117
|
-
code: authorizationCode,
|
|
118
|
-
clientId: GoogleOAuth2Adapter.config.clientId,
|
|
119
|
-
redirectUri: redirectUrl,
|
|
120
|
-
clientSecret: GOOGLE_OAUTH_CLIENT_SECRET,
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
getAccountData: async ({ access_token, id_token }: any) => {
|
|
124
|
-
const response = await fetch(
|
|
125
|
-
`https://people.googleapis.com/v1/people/me?personFields=${GoogleOAuth2Adapter.config.scopes.join(
|
|
126
|
-
',',
|
|
127
|
-
)}`,
|
|
128
|
-
{
|
|
129
|
-
headers: {
|
|
130
|
-
Authorization: `Bearer ${access_token}`,
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
if (response.status === 403) return parseGoogleIdToken(id_token);
|
|
135
|
-
const profileInfoJSON = await response.json();
|
|
136
|
-
if (profileInfoJSON?.error) throw new Error(profileInfoJSON?.error.message);
|
|
137
|
-
|
|
138
|
-
return normalizeProfileData(profileInfoJSON);
|
|
139
|
-
},
|
|
140
|
-
isTokenValid: async (accessToken) => {
|
|
141
|
-
const response = await fetch(
|
|
142
|
-
`https://oauth2.googleapis.com/tokeninfo?id_token=${accessToken?.id_token}`,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const tokenInfo = await response.json();
|
|
146
|
-
|
|
147
|
-
if (tokenInfo.error) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return true;
|
|
152
|
-
},
|
|
153
|
-
refreshToken: async ({ refresh_token }) => {
|
|
154
|
-
const response = await fetch('https://oauth2.googleapis.com/token', {
|
|
155
|
-
method: 'POST',
|
|
156
|
-
// eslint-disable-next-line
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
duplex: 'half',
|
|
159
|
-
headers: {
|
|
160
|
-
'Content-Type': 'application/json',
|
|
161
|
-
},
|
|
162
|
-
body: JSON.stringify({
|
|
163
|
-
client_id: GoogleOAuth2Adapter.config.clientId,
|
|
164
|
-
grant_type: 'refresh_token',
|
|
165
|
-
client_secret: GOOGLE_OAUTH_CLIENT_SECRET,
|
|
166
|
-
refresh_token,
|
|
167
|
-
access_type: 'offline',
|
|
168
|
-
}),
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const refreshedAccessToken = await response.json();
|
|
172
|
-
|
|
173
|
-
return refreshedAccessToken;
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
OAuth2Director.registerAdapter(GoogleOAuth2Adapter);
|
|
180
|
-
|
|
181
|
-
export default GoogleOAuth2Adapter;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/* eslint-disable camelcase */
|
|
2
|
-
import { IOAuth2Adapter } from '@unchainedshop/types/accounts.js';
|
|
3
|
-
import { OAuth2Director, OAuth2Adapter } from '@unchainedshop/core-accountsjs';
|
|
4
|
-
|
|
5
|
-
const { LINKED_IN_OAUTH_CLIENT_ID, LINKED_IN_OAUTH_CLIENT_SECRET } = process.env;
|
|
6
|
-
|
|
7
|
-
const getLinkedInAuthorizationCode = async ({
|
|
8
|
-
code,
|
|
9
|
-
redirectUri,
|
|
10
|
-
clientId,
|
|
11
|
-
clientSecret,
|
|
12
|
-
}): Promise<any> => {
|
|
13
|
-
const response = await fetch('https://www.linkedin.com/oauth/v2/accessToken', {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
duplex: 'half',
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
20
|
-
},
|
|
21
|
-
body: new URLSearchParams({
|
|
22
|
-
code,
|
|
23
|
-
client_id: clientId,
|
|
24
|
-
grant_type: 'authorization_code',
|
|
25
|
-
client_secret: clientSecret,
|
|
26
|
-
redirect_uri: redirectUri,
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return response.json();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const normalizeProfileData = (data): any => {
|
|
34
|
-
const { name, given_name, family_name, email, email_verified, picture, sub } = data;
|
|
35
|
-
return {
|
|
36
|
-
id: sub,
|
|
37
|
-
displayName: name,
|
|
38
|
-
firstName: given_name,
|
|
39
|
-
lastName: family_name,
|
|
40
|
-
email: email_verified ? email : undefined,
|
|
41
|
-
avatarUrl: picture,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const LinkedInOAuthAdapter: IOAuth2Adapter = {
|
|
46
|
-
...OAuth2Adapter,
|
|
47
|
-
key: 'linked-in-oauth2',
|
|
48
|
-
label: 'LinkedIn Oauth',
|
|
49
|
-
version: '1',
|
|
50
|
-
provider: 'linkedin',
|
|
51
|
-
config: {
|
|
52
|
-
clientId: LINKED_IN_OAUTH_CLIENT_ID,
|
|
53
|
-
scopes: ['r_liteprofile', 'r_emailaddress', 'email', 'openid', 'profile'],
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
actions: () => {
|
|
57
|
-
return {
|
|
58
|
-
...OAuth2Adapter.actions(null),
|
|
59
|
-
configurationError: () => {
|
|
60
|
-
return '';
|
|
61
|
-
},
|
|
62
|
-
isActive: () => {
|
|
63
|
-
return Boolean(LINKED_IN_OAUTH_CLIENT_ID && LINKED_IN_OAUTH_CLIENT_SECRET);
|
|
64
|
-
},
|
|
65
|
-
getAuthorizationToken: async (authorizationCode, redirectUrl) => {
|
|
66
|
-
return getLinkedInAuthorizationCode({
|
|
67
|
-
code: authorizationCode,
|
|
68
|
-
clientId: LinkedInOAuthAdapter.config.clientId,
|
|
69
|
-
redirectUri: redirectUrl,
|
|
70
|
-
clientSecret: LINKED_IN_OAUTH_CLIENT_SECRET,
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
getAccountData: async ({ access_token }: any) => {
|
|
74
|
-
const response = await fetch('https://api.linkedin.com/v2/userinfo', {
|
|
75
|
-
headers: {
|
|
76
|
-
Authorization: `Bearer ${access_token}`,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const profileInfoJSON = await response.json();
|
|
81
|
-
|
|
82
|
-
return normalizeProfileData(profileInfoJSON);
|
|
83
|
-
},
|
|
84
|
-
isTokenValid: async ({ access_token }) => {
|
|
85
|
-
const response = await fetch(
|
|
86
|
-
`https://api.linkedin.com/oauth/v2/accessTokenValidation?q=full&access_token=${access_token}`,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const tokenInfo = await response.json();
|
|
90
|
-
|
|
91
|
-
if (tokenInfo.error) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return true;
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
OAuth2Director.registerAdapter(LinkedInOAuthAdapter);
|
|
102
|
-
|
|
103
|
-
export default LinkedInOAuthAdapter;
|