Use OpenOlat endpoint to authenticate

This commit is contained in:
Christian Schweizer 2024-04-30 10:14:38 +02:00
parent d1cb6fc2c9
commit d4d12b4446
2 changed files with 7 additions and 6 deletions

View file

@ -473,7 +473,7 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
.getOrThrow();
final ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setAccessTokenUri(lmsSetup.lmsApiUrl + "/restapi/auth/");
details.setAccessTokenUri(lmsSetup.lmsApiUrl + "/restapi/auth/{username}?password={password}");
details.setClientId(plainClientId.toString());
details.setClientSecret(plainClientSecret.toString());

View file

@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -116,14 +117,14 @@ public class OlatLmsRestTemplate extends RestTemplate {
// Authenticate with OLAT and store the received X-OLAT-TOKEN
this.token = "authenticating";
final String authUrl = this.details.getAccessTokenUri();
final Map<String, String> credentials = new HashMap<>();
credentials.put("username", this.details.getClientId());
credentials.put("password", this.details.getClientSecret());
final Map<String, String> parameters = new HashMap<>();
parameters.put("username", this.details.getClientId());
parameters.put("password", this.details.getClientSecret());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("content-type", "application/json");
final HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(credentials, httpHeaders);
final HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(httpHeaders);
try {
final ResponseEntity<String> response = this.postForEntity(authUrl, requestEntity, String.class);
final ResponseEntity<String> response = this.exchange(authUrl, HttpMethod.GET, requestEntity, String.class, parameters);
final HttpHeaders responseHeaders = response.getHeaders();
if (log.isDebugEnabled()) {