@@ -132,21 +132,14 @@ sub get_credentials ($self) {
132
132
return 0;
133
133
}
134
134
135
- # Determine the user_id to use, if possible.
136
- if (!$ce -> {LTI }{v1p3 }{preferred_source_of_username }) {
137
- warn ' LTI is not properly configured (no preferred_source_of_username). '
138
- . " Please contact your instructor or system administrator.\n " ;
139
- $self -> {error } = $c -> maketext(
140
- ' There was an error during the login process. Please speak to your instructor or system administrator.' );
141
- debug(" No preferred_source_of_username in $ce ->{courseName} so LTIAdvantage::get_credentials is returning 0." );
142
- return 0;
143
- }
135
+ # First check if we already have a user with the current lis_source_did
136
+ my $user = ($c -> db-> getUsersWhere({ lis_source_did => $c -> stash-> {lti_lms_user_id } }))[0] // ' '
137
+ if $c -> stash-> {lti_lms_user_id };
144
138
139
+ my $user_id ;
145
140
my $user_id_source = ' ' ;
146
141
my $type_of_source = ' ' ;
147
142
148
- $self -> {email } = $claims -> {email } // ' ' ;
149
-
150
143
my $extract_claim = sub ($key ) {
151
144
my $value = $claims ;
152
145
for (split ' #' , $key ) {
@@ -159,19 +152,42 @@ sub get_credentials ($self) {
159
152
return $value ;
160
153
};
161
154
162
- if (my $user_id = $extract_claim -> ($ce -> {LTI }{v1p3 }{preferred_source_of_username })) {
163
- $user_id_source = $ce -> {LTI }{v1p3 }{preferred_source_of_username };
164
- $type_of_source = ' preferred_source_of_username' ;
165
- $self -> {user_id } = $user_id ;
166
- }
155
+ if ($user ) {
156
+ $user_id_source = $c -> stash-> {lti_lms_user_id };
157
+ $type_of_source = ' lis_source_did' ;
158
+ $self -> {user_id } = $user -> user_id;
159
+ } else {
160
+ # Determine the user_id to use, if possible.
161
+ if (!$ce -> {LTI }{v1p3 }{preferred_source_of_username }) {
162
+ warn ' LTI is not properly configured (no preferred_source_of_username). '
163
+ . " Please contact your instructor or system administrator.\n " ;
164
+ $self -> {error } = $c -> maketext(
165
+ ' There was an error during the login process. Please speak to your instructor or system administrator.'
166
+ );
167
+ debug(
168
+ " No preferred_source_of_username in $ce ->{courseName} so LTIAdvantage::get_credentials is returning 0."
169
+ );
170
+ return 0;
171
+ }
172
+
173
+ if ($user_id = $extract_claim -> ($ce -> {LTI }{v1p3 }{preferred_source_of_username })) {
174
+ $user_id_source = $ce -> {LTI }{v1p3 }{preferred_source_of_username };
175
+ $type_of_source = ' preferred_source_of_username' ;
176
+ $self -> {user_id } = $user_id ;
177
+ }
167
178
168
- # Fallback if necessary
169
- if (!defined $self -> {user_id } && (my $user_id = $extract_claim -> ($ce -> {LTI }{v1p3 }{fallback_source_of_username }))) {
170
- $user_id_source = $ce -> {LTI }{v1p3 }{fallback_source_of_username };
171
- $type_of_source = ' fallback_source_of_username' ;
172
- $self -> {user_id } = $user_id ;
179
+ # Fallback if necessary
180
+ if (!defined $self -> {user_id }
181
+ && (my $user_id = $extract_claim -> ($ce -> {LTI }{v1p3 }{fallback_source_of_username })))
182
+ {
183
+ $user_id_source = $ce -> {LTI }{v1p3 }{fallback_source_of_username };
184
+ $type_of_source = ' fallback_source_of_username' ;
185
+ $self -> {user_id } = $user_id ;
186
+ }
173
187
}
174
188
189
+ $self -> {email } = $claims -> {email } // ' ' ;
190
+
175
191
if ($self -> {user_id }) {
176
192
# Strip off the part of the address after @ if the email address was used and it was requested to do so.
177
193
$self -> {user_id } =~ s / @.*$// if $user_id_source eq ' email' && $ce -> {LTI }{v1p3 }{strip_domain_from_email };
@@ -188,6 +204,8 @@ sub get_credentials ($self) {
188
204
[ recitation => ' https://purl.imsglobal.org/spec/lti/claim/custom#recitation' ],
189
205
);
190
206
207
+ $self -> {lis_source_did } = $c -> stash-> {lti_lms_user_id } if $c -> stash-> {lti_lms_user_id };
208
+
191
209
$self -> {student_id } =
192
210
$ce -> {LTI }{v1p3 }{preferred_source_of_student_id }
193
211
? ($extract_claim -> ($ce -> {LTI }{v1p3 }{preferred_source_of_student_id }) // ' ' )
0 commit comments