...
|
...
|
@@ -1,5 +1,6 @@
|
1
|
1
|
package im.bci.jb3.dlfp;
|
2
|
2
|
|
|
3
|
+import java.util.Collections;
|
3
|
4
|
import org.apache.commons.logging.LogFactory;
|
4
|
5
|
import org.springframework.beans.factory.annotation.Value;
|
5
|
6
|
import org.springframework.http.HttpEntity;
|
...
|
...
|
@@ -20,7 +21,6 @@ import org.springframework.web.client.RestTemplate;
|
20
|
21
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
21
|
22
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
22
|
23
|
import org.springframework.web.servlet.view.RedirectView;
|
23
|
|
-import org.springframework.web.util.UriComponentsBuilder;
|
24
|
24
|
|
25
|
25
|
@Controller
|
26
|
26
|
@RequestMapping("/dlfp")
|
...
|
...
|
@@ -59,6 +59,7 @@ public class DlfpController {
|
59
|
59
|
HttpHeaders headers = new HttpHeaders();
|
60
|
60
|
headers.add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
61
|
61
|
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
|
62
|
+ headers.add("User-Agent", "jb3");
|
62
|
63
|
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
|
63
|
64
|
requestBody.add("client_id", clientId);
|
64
|
65
|
requestBody.add("client_secret", clientSecret);
|
...
|
...
|
@@ -74,8 +75,11 @@ public class DlfpController {
|
74
|
75
|
|
75
|
76
|
private String retrieveLogin(OauthToken token) {
|
76
|
77
|
RestTemplate restTemplate = new RestTemplate();
|
77
|
|
- String uri = UriComponentsBuilder.fromHttpUrl("https://linuxfr.org/api/v1/me").queryParam("bearer_token", token.getAccess_token()).build().toString();
|
78
|
|
- DlfpMe me = restTemplate.getForObject(uri, DlfpMe.class);
|
|
78
|
+ HttpHeaders headers = new HttpHeaders();
|
|
79
|
+ headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
|
80
|
+ headers.add("User-Agent", "jb3");
|
|
81
|
+ HttpEntity<?> entity = new HttpEntity<>(headers);
|
|
82
|
+ DlfpMe me = restTemplate.exchange("https://linuxfr.org/api/v1/me?bearer_token={bearer_token}", HttpMethod.GET, entity, DlfpMe.class, Collections.singletonMap("bearer_token", token.getAccess_token())).getBody();
|
79
|
83
|
return me.getLogin();
|
80
|
84
|
}
|
81
|
85
|
|
...
|
...
|
@@ -87,6 +91,7 @@ public class DlfpController {
|
87
|
91
|
HttpHeaders headers = new HttpHeaders();
|
88
|
92
|
headers.add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
89
|
93
|
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
|
94
|
+ headers.add("User-Agent", "jb3");
|
90
|
95
|
|
91
|
96
|
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
|
92
|
97
|
requestBody.add("client_id", clientId);
|