74 lines
2.2 KiB
JavaScript
74 lines
2.2 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',
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
console.log('ACCESS_TOKEN', access_token);
|
|
keycloak.query().get('protocol/openid-connect/userinfo').auth(access_token).request((err, res, body) => {
|
|
if (err) {
|
|
console.error(err);
|
|
callback(err);
|
|
} else {
|
|
console.log(body);
|
|
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)
|
|
}
|
|
})()
|