authenticate with OLAT using POST instead of GET

This commit is contained in:
Carol Alexandru 2021-10-13 11:29:02 +02:00
parent dea65b70d2
commit 519ad5a9f8

View file

@ -12,6 +12,7 @@ import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
@ -66,12 +67,16 @@ public class OlatLmsRestTemplate extends RestTemplate {
private void authenticate() {
// Authenticate with OLAT and store the received X-OLAT-TOKEN
this.token = "authenticating";
final String authUrl = String.format("%s%s?password=%s",
this.details.getAccessTokenUri(),
final String authUrl = this.details.getAccessTokenUri();
final String credentials = String.format(
"{\"username\": \"%s\", \"password\": \"%s\"}",
this.details.getClientId(),
this.details.getClientSecret());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("content-type", "application/json");
final HttpEntity<String> requestEntity = new HttpEntity<>(credentials, httpHeaders);
try {
final ResponseEntity<String> response = this.getForEntity(authUrl, String.class);
final ResponseEntity<String> response = this.postForEntity(authUrl, requestEntity, String.class);
final HttpHeaders responseHeaders = response.getHeaders();
log.debug("OLAT [authenticate] {} Headers: {}", response.getStatusCode(), responseHeaders);
this.token = responseHeaders.getFirst("X-OLAT-TOKEN");