Files
cooking-strapi/bin/postinstall.js
Sebastian Seedorf b79abaeba9 Initial Commit
2022-01-30 13:59:20 +01:00

71 lines
2.1 KiB
JavaScript

const fs = require("fs/promises")
;(async () => {
const PATH_BOOTSTRAP = './node_modules/@strapi/plugin-users-permissions/server/bootstrap/index.js'
if (await fs.access(PATH_BOOTSTRAP).then(() => true, () => false)) {
let data = await fs.readFile(PATH_BOOTSTRAP, 'utf8')
data = data.replace(` const grantConfig = {
email: {`, ` const grantConfig = {
keycloak: {
enabled: false,
icon: 'key',
key: '',
secret: '',
oauth: 2,
subdomain: '',
callback: \`\${baseURL}/keycloak/callback\`,
scope: ['profile', 'email', 'roles', 'openid'],
},
email: {`)
await fs.writeFile(PATH_BOOTSTRAP, data, 'utf8')
} else {
console.log("File not found:", PATH_BOOTSTRAP)
}
const PATH_SERVICES = './node_modules/@strapi/plugin-users-permissions/server/services/providers.js'
if (await fs.access(PATH_SERVICES).then(() => true, () => false)) {
let data = await fs.readFile(PATH_SERVICES, 'utf8')
data = data.replace(` switch (provider) {
case 'discord': {`, ` switch (provider) {
case 'keycloak': {
const keycloak = purest({
provider: 'keycloak',
config: {
'keycloak': {
'https://auth.sebse.de/auth/realms/public': {
'__domain': {
'auth': {
'auth': {
'bearer': '[0]'
}
},
},
'{endpoint}': {
'__path': {
'alias': '__default',
}
}
}
}
}
});
keycloak.query().get('protocol/openid-connect/userinfo').auth(access_token).request((err, res, body) => {
if (err) {
callback(err);
} else {
callback(null, {
username: body.preferred_username,
email: body.email
});
}
});
break;
}
case 'discord': {`)
await fs.writeFile(PATH_SERVICES, data, 'utf8')
} else {
console.log("File not found:", PATH_SERVICES)
}
})()