Skip to content
Snippets Groups Projects
Commit 892d828d authored by Martin Vogel's avatar Martin Vogel
Browse files

#414 Finalize vars and update named param

parent 80785696
No related branches found
No related tags found
2 merge requests!2#414 Remaining changes from MR,!1planning#414 Methoden Signaturen (Zwischenstand)
...@@ -3,7 +3,7 @@ package de.fitko.fitconnect.core.auth; ...@@ -3,7 +3,7 @@ package de.fitko.fitconnect.core.auth;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.name.Named; import com.google.inject.name.Named;
import de.fitko.fitconnect.api.domain.auth.OAuthToken; import de.fitko.fitconnect.api.domain.auth.OAuthToken;
import de.fitko.fitconnect.api.exceptions.internal.AuthenticationException; import de.fitko.fitconnect.api.exceptions.AuthenticationException;
import de.fitko.fitconnect.api.services.auth.OAuthService; import de.fitko.fitconnect.api.services.auth.OAuthService;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
...@@ -25,26 +25,26 @@ public class DefaultOAuthService implements OAuthService { ...@@ -25,26 +25,26 @@ public class DefaultOAuthService implements OAuthService {
private final String tokenUrl; private final String tokenUrl;
@Inject @Inject
public DefaultOAuthService(final RestTemplate restTemplate, @Named("authTokenUrl") String tokenUrl) { public DefaultOAuthService(final RestTemplate restTemplate, @Named("environment.authTokenUrl") final String tokenUrl) {
this.restTemplate = restTemplate; this.restTemplate = restTemplate;
this.tokenUrl = tokenUrl; this.tokenUrl = tokenUrl;
} }
@Override @Override
public OAuthToken authenticate(String clientId, String clientSecret, String... scope) throws AuthenticationException { public OAuthToken authenticate(final String clientId, final String clientSecret, final String... scope) throws AuthenticationException {
final String requestBody = buildRequestBody(clientId, clientSecret, scope); final String requestBody = buildRequestBody(clientId, clientSecret, scope);
return performTokenRequest(requestBody); return performTokenRequest(requestBody);
} }
private String buildRequestBody(String clientId, String clientSecret, String... scope) { private String buildRequestBody(final String clientId, final String clientSecret, final String... scope) {
var data = new HashMap<String, String>() {{ final var data = new HashMap<String, String>() {{
put("grant_type", "client_credentials"); put("grant_type", "client_credentials");
put("client_id", clientId); put("client_id", clientId);
put("client_secret", clientSecret); put("client_secret", clientSecret);
}}; }};
if(scope.length > 0){ if (scope.length > 0) {
data.put("scope", String.join(",", scope)); data.put("scope", String.join(",", scope));
} }
...@@ -62,7 +62,7 @@ public class DefaultOAuthService implements OAuthService { ...@@ -62,7 +62,7 @@ public class DefaultOAuthService implements OAuthService {
} }
private HttpHeaders getHeaders() { private HttpHeaders getHeaders() {
var headers = new HttpHeaders(); final var headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAcceptCharset(List.of(StandardCharsets.UTF_8)); headers.setAcceptCharset(List.of(StandardCharsets.UTF_8));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment