Skip to content

Commit 754004e

Browse files
committed
Use alternatename as username if authenticated using GakuNinLMS's LTI plugin
1 parent eb79f50 commit 754004e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

xapi_stmt_gen/xapi_stmt_gen/generator.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,7 +3700,7 @@ module.exports = async function main() { // eslint-disable-line max-statements
37003700

37013701
// Retrieve all users
37023702
const users = await USER.findAll({
3703-
attributes: ['id', 'username'],
3703+
attributes: ['id', 'auth', 'username', 'alternatename'],
37043704
raw: true
37053705
}).catch(err => {
37063706
process.exitCode = 1;
@@ -3719,18 +3719,20 @@ module.exports = async function main() { // eslint-disable-line max-statements
37193719
let userAttrs = [];
37203720
let newEppns = [];
37213721
for (const user of users) {
3722+
// Use alternatename as username if authenticated using GakuNinLMS's LTI plugin
3723+
const username = (user.auth = 'lti' && config.LRS.ePPNScoped) ? user.alternatename : user.username;
37223724
const eppn = eppns.find((eppn) => {
3723-
if (eppn['username'] === user.username) {
3725+
if (eppn['username'] === username) {
37243726
return eppn;
37253727
}
37263728
});
37273729
if (eppn) {
37283730
userAttrs[user.id] = eppn;
37293731
} else {
3730-
const hash = crypto.createHash('sha256').update(user.username).digest('hex');
3731-
const scope = getScopeFromEppn(user.username);
3732+
const hash = crypto.createHash('sha256').update(username).digest('hex');
3733+
const scope = getScopeFromEppn(username);
37323734
userAttrs[user.id] = {
3733-
username: user.username, // may not be ePPN format
3735+
username: username, // may not be ePPN format
37343736
hash: hash,
37353737
scope: scope, // nullable
37363738
acl: scope ? scope.replace(/[.-]/g, '_') : null // used for RLS

0 commit comments

Comments
 (0)