@@ -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,25 @@ 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
3723+ // if authenticated using GakuNinLMS's LTI plugin
3724+ const username = (
3725+ ( user . auth === 'lti' && config . LRS . ePPNScoped )
3726+ ? user . alternatename
3727+ : user . username
3728+ ) ;
37223729 const eppn = eppns . find ( ( eppn ) => {
3723- if ( eppn [ 'username' ] === user . username ) {
3730+ if ( eppn [ 'username' ] === username ) {
37243731 return eppn ;
37253732 }
37263733 } ) ;
37273734 if ( eppn ) {
37283735 userAttrs [ user . id ] = eppn ;
37293736 } else {
3730- const hash = crypto . createHash ( 'sha256' ) . update ( user . username ) . digest ( 'hex' ) ;
3731- const scope = getScopeFromEppn ( user . username ) ;
3737+ const hash = crypto . createHash ( 'sha256' ) . update ( username ) . digest ( 'hex' ) ;
3738+ const scope = getScopeFromEppn ( username ) ;
37323739 userAttrs [ user . id ] = {
3733- username : user . username , // may not be ePPN format
3740+ username : username , // may not be ePPN format
37343741 hash : hash ,
37353742 scope : scope , // nullable
37363743 acl : scope ? scope . replace ( / [ . - ] / g, '_' ) : null // used for RLS
0 commit comments