Skip to content

Commit

Permalink
Merge pull request strapi#11708 from strapi/v4/fix-defaults-provider
Browse files Browse the repository at this point in the history
Remove defaults key from stored grant config
  • Loading branch information
alexandrebodin authored Nov 29, 2021
2 parents 760efb8 + b0b4135 commit 6e0f205
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
3 changes: 0 additions & 3 deletions packages/plugins/users-permissions/server/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ const initGrant = async pluginStore => {
const baseURL = `${strapi.config.server.url}/${apiPrefix}/auth`;

const grantConfig = {
defaults: {
prefix: `${apiPrefix}/connect`,
},
email: {
enabled: true,
icon: 'envelope',
Expand Down
10 changes: 9 additions & 1 deletion packages/plugins/users-permissions/server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,18 @@ module.exports = {
async connect(ctx, next) {
const grant = require('grant-koa');

const grantConfig = await strapi
const providers = await strapi
.store({ type: 'plugin', name: 'users-permissions', key: 'grant' })
.get();

const apiPrefix = strapi.config.get('api.rest.prefix');
const grantConfig = {
defaults: {
prefix: `${apiPrefix}/connect`,
},
...providers,
};

const [requestPath] = ctx.request.url.split('?');
const provider = requestPath.split('/connect/')[1].split('/')[0];

Expand Down
20 changes: 10 additions & 10 deletions packages/plugins/users-permissions/server/services/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = ({ strapi }) => {
const getProfile = async (provider, query, callback) => {
const access_token = query.access_token || query.code || query.oauth_token;

const grant = await strapi
const providers = await strapi
.store({ type: 'plugin', name: 'users-permissions', key: 'grant' })
.get();

Expand Down Expand Up @@ -168,7 +168,7 @@ module.exports = ({ strapi }) => {
return callback(null, {
username: userbody.login,
email: Array.isArray(emailsbody)
? emailsbody.find((email) => email.primary === true).email
? emailsbody.find(email => email.primary === true).email
: null,
});
});
Expand Down Expand Up @@ -201,8 +201,8 @@ module.exports = ({ strapi }) => {
const twitter = purest({
provider: 'twitter',
config: purestConfig,
key: grant.twitter.key,
secret: grant.twitter.secret,
key: providers.twitter.key,
secret: providers.twitter.secret,
});

twitter
Expand All @@ -225,8 +225,8 @@ module.exports = ({ strapi }) => {
case 'instagram': {
const instagram = purest({
provider: 'instagram',
key: grant.instagram.key,
secret: grant.instagram.secret,
key: providers.instagram.key,
secret: providers.instagram.secret,
config: purestConfig,
});

Expand Down Expand Up @@ -298,7 +298,7 @@ module.exports = ({ strapi }) => {

twitch
.get('users')
.auth(access_token, grant.twitch.key)
.auth(access_token, providers.twitch.key)
.request((err, res, body) => {
if (err) {
callback(err);
Expand Down Expand Up @@ -403,7 +403,7 @@ module.exports = ({ strapi }) => {
}
case 'auth0': {
const purestAuth0Conf = {};
purestAuth0Conf[`https://${grant.auth0.subdomain}.auth0.com`] = {
purestAuth0Conf[`https://${providers.auth0.subdomain}.auth0.com`] = {
__domain: {
auth: {
auth: { bearer: '[0]' },
Expand Down Expand Up @@ -442,7 +442,7 @@ module.exports = ({ strapi }) => {
break;
}
case 'cas': {
const provider_url = 'https://' + _.get(grant['cas'], 'subdomain');
const provider_url = 'https://' + _.get(providers.cas, 'subdomain');
const cas = purest({
provider: 'cas',
config: {
Expand Down Expand Up @@ -551,7 +551,7 @@ module.exports = ({ strapi }) => {
}

if (
!_.isEmpty(_.find(users, (user) => user.provider !== provider)) &&
!_.isEmpty(_.find(users, user => user.provider !== provider)) &&
advanced.unique_email
) {
return resolve([
Expand Down

0 comments on commit 6e0f205

Please sign in to comment.