mirror of
https://github.com/strapi/strapi.git
synced 2025-10-04 04:42:47 +00:00

* cron type fix * Fix typo of query key from 'providers' to 'get-providers' * Closing #19644 fix filters type * node-scadule updated + types updated * Fix formating errors * fix formatting * update lock file * fix patreon oauth 400 error from lack of user-agent header * test: backport cli tests (#20433) * fix(chore): increase specificity of the Lightning icon color (#20467) * test: temporarily disable broken edit ctb tests on CI (#20481) * feat(cli): cloud cli commands (v4) (#20119) * feat(cli): add cloud commands Co-authored-by: Gonzalo Garcia <nouvellegon@gmail.com> Co-authored-by: nathan-pichon <nathan.pichon@strapi.io> Co-authored-by: Abdallah M <55534657+abdallahmz@users.noreply.github.com> * v4.25.0 (#20500) * NPS: Update frequency of the NPS (#20492) * enhancement(admin): change postFirstDismissal and display delays * enhancement(admin): change the display delay * fix: prevent use of local ips on webhooks (#20487) * chore: mask error on webhook manual trigger * feat: prevent using local ips * feat: display webhook edit error * chore: pr suggestion * chore: api tests * chore: allow local ips on development * chore: only run check on production * feat: include internationalized urls * fix: prettier * Add: Strapi deploy command to README files * v4.25.1 * Update @aws-sdk/client-s3 package * feat(cli): add browser logout step (#20502) * feat(cli): add browser log out step * handle error whiile fetching the config * Update LICENSE packing for packages for v4 (#20576) * feat(create-strapi-app): remove the cloud project creation part (#20561) * feat(create-strapi-app): remove the cloud project creation part * fix(create-strapi-app): adding new parameter to cloud service instantiation * Update Yarn to 4.3.1 Signed-off-by: Sora Morimoto <sora@morimoto.io> * feat(cli): trigger login sequence when token is missing or invalid (#20572) * feat(cli): launch login when auth fails * fix(cli): abstract create project fn * fix(cli): guidelines * fix(cli): rebase --------- Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> * fix clone entity, #20509 (#20531) * chore: bump glob from 7.2.0 to 9.0.0 * chore: bump glob to v10.4.2 in core/strapi * update yarn.lock * removed redundant packages/core/strapi/src/load/glob.ts file * v4.25.2 to main (#20676) * Fix typo of query key from 'providers' to 'get-providers' * Closing #19644 fix filters type * fix patreon oauth 400 error from lack of user-agent header * Add: Strapi deploy command to README files * Update @aws-sdk/client-s3 package * feat(cli): add browser logout step (#20502) * feat(cli): add browser log out step * handle error whiile fetching the config * Update LICENSE packing for packages for v4 (#20576) * feat(create-strapi-app): remove the cloud project creation part (#20561) * feat(create-strapi-app): remove the cloud project creation part * fix(create-strapi-app): adding new parameter to cloud service instantiation * Update Yarn to 4.3.1 Signed-off-by: Sora Morimoto <sora@morimoto.io> * feat(cli): trigger login sequence when token is missing or invalid (#20572) * feat(cli): launch login when auth fails * fix(cli): abstract create project fn * fix(cli): guidelines * fix(cli): rebase --------- Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> * fix: support string array * fix clone entity, #20509 (#20531) * v4.25.2 --------- Signed-off-by: Sora Morimoto <sora@morimoto.io> Co-authored-by: smoothdvd <madfxgao@gmail.com> Co-authored-by: Micah Riggan <micahriggan@gmail.com> Co-authored-by: Tewson Seeoun <tewson.seeoun@gmail.com> Co-authored-by: Maxime Castres <mcastres@student.42.fr> Co-authored-by: Alex Supkay <asupkay1124@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> Co-authored-by: Abdallah M <55534657+abdallahmz@users.noreply.github.com> Co-authored-by: Jean-Sébastien Herbaux <jean-sebastien.herbaux@epitech.eu> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Sora Morimoto <sora@morimoto.io> Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Kirill Verevkin <kira795@yandex.ru> * v4.25.2 (#20675) * fix: support string array * v4.25.2 --------- Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> * feat(cli): use project name from package json by default (#20479) * chore: change cloud message in homepage (#20685) * chore(cloud-cli): migrate to fs-extra (#20695) * feat(cloud-cli): migrate compress-files.ts to fs-extra * feat(cloud-cli): migrate pkg.ts to fs-extra * fix(cloud-cli): update using promises in recursive function * feat(cli): Add projects list command (#20694) * feat(cli): projects list command * fix: updating contributing guide workflow * chore: release v4.25.3 (#20722) * fix: invalid path separator (#20740) * fix: invalid path separator * fix: prettier * v4.25.4 to develop (#20832) * 4.25.4 to main (#20833) * cron type fix * node-scadule updated + types updated * Fix formating errors * fix formatting * update lock file * chore(cloud-cli): migrate to fs-extra (#20695) * feat(cloud-cli): migrate compress-files.ts to fs-extra * feat(cloud-cli): migrate pkg.ts to fs-extra * fix(cloud-cli): update using promises in recursive function * feat(cli): Add projects list command (#20694) * feat(cli): projects list command * fix: invalid path separator (#20740) * fix: invalid path separator * fix: prettier * v4.25.4 --------- Co-authored-by: Boegie19 <34578426+Boegie19@users.noreply.github.com> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> * Chore: Removing some people from the issue auto-assignment Removing Simen and Nick from the array of people issues will be auto-assigned to * fix(cloud-cli): avoid blocking event loop in deploy command (#20850) * chore(cloud-cli): update error handling for config and logs at the ends of function execution * fix(cloud-cli): clear timeout before returning - free the event loop from waiting * feat(cli): add project link command to cloud cli (#20714) * feat(cli): add link command * 4.25.5 to main (#20873) * cron type fix * node-scadule updated + types updated * Fix formating errors * fix formatting * update lock file * chore(cloud-cli): migrate to fs-extra (#20695) * feat(cloud-cli): migrate compress-files.ts to fs-extra * feat(cloud-cli): migrate pkg.ts to fs-extra * fix(cloud-cli): update using promises in recursive function * feat(cli): Add projects list command (#20694) * feat(cli): projects list command * fix: updating contributing guide workflow * fix: invalid path separator (#20740) * fix: invalid path separator * fix: prettier * v4.25.4 to develop (#20832) * Chore: Removing some people from the issue auto-assignment Removing Simen and Nick from the array of people issues will be auto-assigned to * fix(cloud-cli): avoid blocking event loop in deploy command (#20850) * chore(cloud-cli): update error handling for config and logs at the ends of function execution * fix(cloud-cli): clear timeout before returning - free the event loop from waiting * feat(cli): add project link command to cloud cli (#20714) * feat(cli): add link command * v4.25.5 --------- Co-authored-by: Boegie19 <34578426+Boegie19@users.noreply.github.com> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> Co-authored-by: José Luis <alagunasalahaddin@live.com> Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> Co-authored-by: DMehaffy <derrickmehaffy@gmail.com> * v4.25.5 to develop (#20872) * 4.25.4 to main (#20833) * cron type fix * node-scadule updated + types updated * Fix formating errors * fix formatting * update lock file * chore(cloud-cli): migrate to fs-extra (#20695) * feat(cloud-cli): migrate compress-files.ts to fs-extra * feat(cloud-cli): migrate pkg.ts to fs-extra * fix(cloud-cli): update using promises in recursive function * feat(cli): Add projects list command (#20694) * feat(cli): projects list command * fix: invalid path separator (#20740) * fix: invalid path separator * fix: prettier * v4.25.4 --------- Co-authored-by: Boegie19 <34578426+Boegie19@users.noreply.github.com> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> * v4.25.5 --------- Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> Co-authored-by: Boegie19 <34578426+Boegie19@users.noreply.github.com> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Gonzalo Andres Garcia <nouvellegon@gmail.com> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> * fix custom email provider test issue #19122 (#19123) * fix custom email provider test issue #19122 * chore(email): prettier clean up --------- Co-authored-by: Jamie Howard <jamie.howard@strapi.io> * Changed Discord username to fit change Discord made. * v4.25.6 * fix(cli): Update 'project not found' error message in deploy command (#20923) * chore: aggregate test result to add a single required status check and make it dynamic * shard ee tests+ fix broken platform (#20914) * v4.25.7 * RBAC Action Aliases - v4 (#20954) * test(cli): add list command tests (#20949) * feat(cloud-cli): preselect node-version based on local node-version (#20959) * [Fix] Validate cloning as entity creation so field validations aren't skipped e.g. unique constraints (#20963) * flatten CI workflow tests (#20969) * v4.25.8 release to develop (#21011) * Removing workflows the support team doesn't need anymore * chore: getstarted schema sync between v4-v5 (#21047) * Chore(CLI): Add validation to prevent deployment of suspended projects (#20976) * chore(cli): check project suspension * Prettier fix * chore(deps): update axios to 1.7.4 (#21014) * fix(cli): Update endpoint path for listLinkProjects (#21052) * chore: update lint-staged to 15.2.9 (#21075) * v4.25.9 * fix: issue 21079 * fix: rich text selection & deletion issues * fix: build * fix: type * fix: skip failing cli tests * chore: fix jest options in ci --------- Signed-off-by: Sora Morimoto <sora@morimoto.io> Co-authored-by: Boegie19 <34578426+Boegie19@users.noreply.github.com> Co-authored-by: smoothdvd <madfxgao@gmail.com> Co-authored-by: Micah Riggan <micahriggan@gmail.com> Co-authored-by: Tewson Seeoun <tewson.seeoun@gmail.com> Co-authored-by: Ben Irvin <ben.irvin@strapi.io> Co-authored-by: Simone <startae14@gmail.com> Co-authored-by: Nathan Pichon <nathan.pichon@strapi.io> Co-authored-by: Gonzalo Garcia <nouvellegon@gmail.com> Co-authored-by: Abdallah M <55534657+abdallahmz@users.noreply.github.com> Co-authored-by: Maxime Castres <mcastres@student.42.fr> Co-authored-by: Convly <jean-sebastien.herbaux@epitech.eu> Co-authored-by: Alex Supkay <asupkay1124@gmail.com> Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com> Co-authored-by: Sora Morimoto <sora@morimoto.io> Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com> Co-authored-by: Kirill Verevkin <kira795@yandex.ru> Co-authored-by: chrismuiruriz <chrismuiruri007@gmail.com> Co-authored-by: José Luis <alagunasalahaddin@live.com> Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> Co-authored-by: Rémi de Juvigny <remi.dejuvigny@strapi.io> Co-authored-by: DMehaffy <derrickmehaffy@gmail.com> Co-authored-by: ahallaha <104538552+ahallaha@users.noreply.github.com> Co-authored-by: Jamie Howard <jamie.howard@strapi.io> Co-authored-by: mallowsc <mallowsc@outlook.com> Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> Co-authored-by: mallowsc <96073136+mallowsc@users.noreply.github.com> Co-authored-by: Olli Hiekkaranta <Ohiekkar@users.noreply.github.com>
568 lines
14 KiB
JavaScript
568 lines
14 KiB
JavaScript
'use strict';
|
|
|
|
const { strict: assert } = require('assert');
|
|
const jwt = require('jsonwebtoken');
|
|
const urljoin = require('url-join');
|
|
const jwkToPem = require('jwk-to-pem');
|
|
|
|
const getCognitoPayload = async ({ idToken, jwksUrl, purest }) => {
|
|
const {
|
|
header: { kid },
|
|
payload,
|
|
} = jwt.decode(idToken, { complete: true });
|
|
|
|
if (!payload || !kid) {
|
|
throw new Error('The provided token is not valid');
|
|
}
|
|
|
|
const config = {
|
|
cognito: {
|
|
discovery: {
|
|
origin: jwksUrl.origin,
|
|
path: jwksUrl.pathname,
|
|
},
|
|
},
|
|
};
|
|
try {
|
|
const cognito = purest({ provider: 'cognito', config });
|
|
// get the JSON Web Key (JWK) for the user pool
|
|
const { body: jwk } = await cognito('discovery').request();
|
|
// Get the key with the same Key ID as the provided token
|
|
const key = jwk.keys.find(({ kid: jwkKid }) => jwkKid === kid);
|
|
const pem = jwkToPem(key);
|
|
|
|
// https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html
|
|
const decodedToken = await new Promise((resolve, reject) => {
|
|
jwt.verify(idToken, pem, { algorithms: ['RS256'] }, (err, decodedToken) => {
|
|
if (err) {
|
|
reject();
|
|
}
|
|
resolve(decodedToken);
|
|
});
|
|
});
|
|
return decodedToken;
|
|
} catch (err) {
|
|
throw new Error('There was an error verifying the token');
|
|
}
|
|
};
|
|
|
|
const initProviders = ({ baseURL, purest }) => ({
|
|
email: {
|
|
enabled: true,
|
|
icon: 'envelope',
|
|
grantConfig: {},
|
|
},
|
|
discord: {
|
|
enabled: false,
|
|
icon: 'discord',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/discord/callback`,
|
|
scope: ['identify', 'email'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const discord = purest({ provider: 'discord' });
|
|
|
|
return discord
|
|
.get('users/@me')
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => {
|
|
// Combine username and discriminator (if discriminator exists and not equal to 0)
|
|
const username =
|
|
body.discriminator && body.discriminator !== '0'
|
|
? `${body.username}#${body.discriminator}`
|
|
: body.username;
|
|
return {
|
|
username,
|
|
email: body.email,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
facebook: {
|
|
enabled: false,
|
|
icon: 'facebook-square',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/facebook/callback`,
|
|
scope: ['email'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const facebook = purest({ provider: 'facebook' });
|
|
|
|
return facebook
|
|
.get('me')
|
|
.auth(accessToken)
|
|
.qs({ fields: 'name,email' })
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.name,
|
|
email: body.email,
|
|
}));
|
|
},
|
|
},
|
|
google: {
|
|
enabled: false,
|
|
icon: 'google',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/google/callback`,
|
|
scope: ['email'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const google = purest({ provider: 'google' });
|
|
|
|
return google
|
|
.query('oauth')
|
|
.get('tokeninfo')
|
|
.qs({ accessToken })
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.email.split('@')[0],
|
|
email: body.email,
|
|
}));
|
|
},
|
|
},
|
|
github: {
|
|
enabled: false,
|
|
icon: 'github',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/github/callback`,
|
|
scope: ['user', 'user:email'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const github = purest({
|
|
provider: 'github',
|
|
defaults: {
|
|
headers: {
|
|
'user-agent': 'strapi',
|
|
},
|
|
},
|
|
});
|
|
|
|
const { body: userBody } = await github.get('user').auth(accessToken).request();
|
|
|
|
// This is the public email on the github profile
|
|
if (userBody.email) {
|
|
return {
|
|
username: userBody.login,
|
|
email: userBody.email,
|
|
};
|
|
}
|
|
// Get the email with Github's user/emails API
|
|
const { body: emailBody } = await github.get('user/emails').auth(accessToken).request();
|
|
|
|
return {
|
|
username: userBody.login,
|
|
email: Array.isArray(emailBody)
|
|
? emailBody.find((email) => email.primary === true).email
|
|
: null,
|
|
};
|
|
},
|
|
},
|
|
microsoft: {
|
|
enabled: false,
|
|
icon: 'windows',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/microsoft/callback`,
|
|
scope: ['user.read'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const microsoft = purest({ provider: 'microsoft' });
|
|
|
|
return microsoft
|
|
.get('me')
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.userPrincipalName,
|
|
email: body.userPrincipalName,
|
|
}));
|
|
},
|
|
},
|
|
|
|
twitter: {
|
|
enabled: false,
|
|
icon: 'twitter',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/twitter/callback`,
|
|
},
|
|
async authCallback({ accessToken, query, providers }) {
|
|
const twitter = purest({
|
|
provider: 'twitter',
|
|
defaults: {
|
|
oauth: {
|
|
consumer_key: providers.twitter.key,
|
|
consumer_secret: providers.twitter.secret,
|
|
},
|
|
},
|
|
});
|
|
|
|
return twitter
|
|
.get('account/verify_credentials')
|
|
.auth(accessToken, query.access_secret)
|
|
.qs({ screen_name: query['raw[screen_name]'], include_email: 'true' })
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.screen_name,
|
|
email: body.email,
|
|
}));
|
|
},
|
|
},
|
|
instagram: {
|
|
enabled: false,
|
|
icon: 'instagram',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/instagram/callback`,
|
|
scope: ['user_profile'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const instagram = purest({ provider: 'instagram' });
|
|
|
|
return instagram
|
|
.get('me')
|
|
.auth(accessToken)
|
|
.qs({ fields: 'id,username' })
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.username,
|
|
email: `${body.username}@strapi.io`, // dummy email as Instagram does not provide user email
|
|
}));
|
|
},
|
|
},
|
|
vk: {
|
|
enabled: false,
|
|
icon: 'vk',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/vk/callback`,
|
|
scope: ['email'],
|
|
},
|
|
async authCallback({ accessToken, query }) {
|
|
const vk = purest({ provider: 'vk' });
|
|
|
|
return vk
|
|
.get('users')
|
|
.auth(accessToken)
|
|
.qs({ id: query.raw.user_id, v: '5.122' })
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: `${body.response[0].last_name} ${body.response[0].first_name}`,
|
|
email: query.raw.email,
|
|
}));
|
|
},
|
|
},
|
|
|
|
twitch: {
|
|
enabled: false,
|
|
icon: 'twitch',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/twitch/callback`,
|
|
scope: ['user:read:email'],
|
|
},
|
|
async authCallback({ accessToken, providers }) {
|
|
const twitch = purest({
|
|
provider: 'twitch',
|
|
config: {
|
|
twitch: {
|
|
default: {
|
|
origin: 'https://api.twitch.tv',
|
|
path: 'helix/{path}',
|
|
headers: {
|
|
Authorization: 'Bearer {auth}',
|
|
'Client-Id': '{auth}',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return twitch
|
|
.get('users')
|
|
.auth(accessToken, providers.twitch.key)
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.data[0].login,
|
|
email: body.data[0].email,
|
|
}));
|
|
},
|
|
},
|
|
|
|
linkedin: {
|
|
enabled: false,
|
|
icon: 'linkedin',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callbackUrl: `${baseURL}/linkedin/callback`,
|
|
scope: ['r_liteprofile', 'r_emailaddress'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const linkedIn = purest({ provider: 'linkedin' });
|
|
const {
|
|
body: { localizedFirstName },
|
|
} = await linkedIn.get('me').auth(accessToken).request();
|
|
const {
|
|
body: { elements },
|
|
} = await linkedIn
|
|
.get('emailAddress?q=members&projection=(elements*(handle~))')
|
|
.auth(accessToken)
|
|
.request();
|
|
|
|
const email = elements[0]['handle~'];
|
|
|
|
return {
|
|
username: localizedFirstName,
|
|
email: email.emailAddress,
|
|
};
|
|
},
|
|
},
|
|
|
|
cognito: {
|
|
enabled: false,
|
|
icon: 'aws',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
subdomain: 'my.subdomain.com',
|
|
callback: `${baseURL}/cognito/callback`,
|
|
scope: ['email', 'openid', 'profile'],
|
|
},
|
|
async authCallback({ query, providers }) {
|
|
const jwksUrl = new URL(providers.cognito.jwksurl);
|
|
const idToken = query.id_token;
|
|
const tokenPayload = await getCognitoPayload({ idToken, jwksUrl, purest });
|
|
return {
|
|
username: tokenPayload['cognito:username'],
|
|
email: tokenPayload.email,
|
|
};
|
|
},
|
|
},
|
|
|
|
reddit: {
|
|
enabled: false,
|
|
icon: 'reddit',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callback: `${baseURL}/reddit/callback`,
|
|
scope: ['identity'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const reddit = purest({
|
|
provider: 'reddit',
|
|
config: {
|
|
reddit: {
|
|
default: {
|
|
origin: 'https://oauth.reddit.com',
|
|
path: 'api/{version}/{path}',
|
|
version: 'v1',
|
|
headers: {
|
|
Authorization: 'Bearer {auth}',
|
|
'user-agent': 'strapi',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return reddit
|
|
.get('me')
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => ({
|
|
username: body.name,
|
|
email: `${body.name}@strapi.io`, // dummy email as Reddit does not provide user email
|
|
}));
|
|
},
|
|
},
|
|
|
|
auth0: {
|
|
enabled: false,
|
|
icon: '',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
subdomain: 'my-tenant.eu',
|
|
callback: `${baseURL}/auth0/callback`,
|
|
scope: ['openid', 'email', 'profile'],
|
|
},
|
|
async authCallback({ accessToken, providers }) {
|
|
const auth0 = purest({ provider: 'auth0' });
|
|
|
|
return auth0
|
|
.get('userinfo')
|
|
.subdomain(providers.auth0.subdomain)
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => {
|
|
const username = body.username || body.nickname || body.name || body.email.split('@')[0];
|
|
const email = body.email || `${username.replace(/\s+/g, '.')}@strapi.io`;
|
|
|
|
return {
|
|
username,
|
|
email,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
|
|
cas: {
|
|
enabled: false,
|
|
icon: 'book',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callback: `${baseURL}/cas/callback`,
|
|
scope: ['openid email'], // scopes should be space delimited
|
|
subdomain: 'my.subdomain.com/cas',
|
|
},
|
|
async authCallback({ accessToken, providers }) {
|
|
const cas = purest({ provider: 'cas' });
|
|
|
|
return cas
|
|
.get('oidc/profile')
|
|
.subdomain(providers.cas.subdomain)
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => {
|
|
// CAS attribute may be in body.attributes or "FLAT", depending on CAS config
|
|
const username = body.attributes
|
|
? body.attributes.strapiusername || body.id || body.sub
|
|
: body.strapiusername || body.id || body.sub;
|
|
const email = body.attributes
|
|
? body.attributes.strapiemail || body.attributes.email
|
|
: body.strapiemail || body.email;
|
|
if (!username || !email) {
|
|
strapi.log.warn(
|
|
`CAS Response Body did not contain required attributes: ${JSON.stringify(body)}`
|
|
);
|
|
}
|
|
return {
|
|
username,
|
|
email,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
|
|
patreon: {
|
|
enabled: false,
|
|
icon: '',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
callback: `${baseURL}/patreon/callback`,
|
|
scope: ['identity', 'identity[email]'],
|
|
},
|
|
async authCallback({ accessToken }) {
|
|
const patreon = purest({
|
|
provider: 'patreon',
|
|
config: {
|
|
patreon: {
|
|
default: {
|
|
origin: 'https://www.patreon.com',
|
|
path: 'api/oauth2/{path}',
|
|
headers: {
|
|
authorization: 'Bearer {auth}',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return patreon
|
|
.get('v2/identity')
|
|
.auth(accessToken)
|
|
.qs(new URLSearchParams({ 'fields[user]': 'full_name,email' }).toString())
|
|
.request()
|
|
.then(({ body }) => {
|
|
const patreonData = body.data.attributes;
|
|
return {
|
|
username: patreonData.full_name,
|
|
email: patreonData.email,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
keycloack: {
|
|
enabled: false,
|
|
icon: '',
|
|
grantConfig: {
|
|
key: '',
|
|
secret: '',
|
|
subdomain: 'myKeycloakProvider.com/realms/myrealm',
|
|
callback: `${baseURL}/keycloak/callback`,
|
|
scope: ['openid', 'email', 'profile'],
|
|
},
|
|
async authCallback({ accessToken, providers }) {
|
|
const keycloak = purest({ provider: 'keycloak' });
|
|
|
|
return keycloak
|
|
.subdomain(providers.keycloak.subdomain)
|
|
.get('protocol/openid-connect/userinfo')
|
|
.auth(accessToken)
|
|
.request()
|
|
.then(({ body }) => {
|
|
return {
|
|
username: body.preferred_username,
|
|
email: body.email,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
});
|
|
|
|
module.exports = () => {
|
|
const purest = require('purest');
|
|
|
|
const apiPrefix = strapi.config.get('api.rest.prefix');
|
|
const baseURL = urljoin(strapi.config.server.url, apiPrefix, 'auth');
|
|
|
|
const authProviders = initProviders({ baseURL, purest });
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
return {
|
|
getAll() {
|
|
return authProviders;
|
|
},
|
|
get(name) {
|
|
return authProviders[name];
|
|
},
|
|
add(name, config) {
|
|
authProviders[name] = config;
|
|
},
|
|
remove(name) {
|
|
delete authProviders[name];
|
|
},
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
async run({ provider, accessToken, query, providers }) {
|
|
const authProvider = authProviders[provider];
|
|
|
|
assert(authProvider, 'Unknown auth provider');
|
|
|
|
return authProvider.authCallback({ accessToken, query, providers, purest });
|
|
},
|
|
};
|
|
};
|