我没有使用REST API从Linked In接收访问令牌。 虽然相同的代码在过去的一个月内正在运行,但现在它突然停止工作,因为自上一周以来 JAVA代码如下带注释
@RequestMapping(value = "partauth/linkedin/access")
public String linkedinAccess(@RequestParam("code") String authCode,
@RequestParam("state") String state,
@RequestHeader(value = "User-Agent") String userAgent)
throws Exception {
JsonNode root = null;
String forwardURL = null;
//System.out.println("LinkedinConnect.linkedinaccess()" + authCode);
/*
* put a check for crossite
*/
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(configBean.getEncLinkedInAccessURL());
// add header
post.setHeader("User-Agent", userAgent);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("grant_type",
"authorization_code"));
urlParameters.add(new BasicNameValuePair("code", authCode));
urlParameters.add(new BasicNameValuePair("redirect_uri", configBean
.getEncLinkedInRedirectUri()));
urlParameters.add(new BasicNameValuePair("client_id", configBean
.getEncLinkedInClientId()));
urlParameters.add(new BasicNameValuePair("client_secret", configBean
.getEncLinkedInClientSecret()));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
System.out.println("LinkedInController.linkedinAccess()" + configBean
.getEncLinkedInRedirectUri() + " " + configBean
.getEncLinkedInClientId() + " " + configBean
.getEncLinkedInClientSecret() + " " + configBean.getEncLinkedInAccessURL());
for(int i=0; i < response.getAllHeaders().length; i++)
{
Header header = response.getAllHeaders()[i];
System.out.println("LinkedInController.linkedinAccess()" + header.getName());
System.out.println("LinkedInController.linkedinAccess()" +header.getValue());
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String responseBody = reader.readLine();
// get access token and email of the person from linked in and pass
// it on to the userauth
ObjectMapper mapper = new ObjectMapper();
root = mapper.readTree(responseBody);
String accessToken = root.get("access_token").asText();
// String inputLine;
System.out.println("SignInController.linkedinaccess() ACCESS TOKEN"
+ accessToken);
postLinkedInSocialLogin.initiate(accessToken);
String retVal = "redirect:/portaluser/portaluser.html";
if(((UserAuthCredentials)SecurityContextHolder.getContext().getAuthentication()).getUserSessionInformation().containsKey(EnumeratedTypes.UserSessionData.ADDITIONALLOGINFLOW))
{
/*
* do nothing in terms of redirection
* just return
*/
((UserAuthCredentials)SecurityContextHolder.getContext().getAuthentication()).getUserSessionInformation().remove(EnumeratedTypes.UserSessionData.ADDITIONALLOGINFLOW);
retVal ="redirect:/login/windowclose.html";
}
return retVal;
}
我从链接获得的响应是所有响应标头:
LinkedInController.linkedinAccess()Date
LinkedInController.linkedinAccess()Mon, 04 May 2015 08:42:50 GMT
LinkedInController.linkedinAccess()Cache-Control
LinkedInController.linkedinAccess()no-store
LinkedInController.linkedinAccess()Location
LinkedInController.linkedinAccess()https://www.linkedin.com/uas/oauth2/accessToken
LinkedInController.linkedinAccess()Content-Type
LinkedInController.linkedinAccess()text/html
LinkedInController.linkedinAccess()Content-Language
LinkedInController.linkedinAccess()en
LinkedInController.linkedinAccess()X-Li-Pop
LinkedInController.linkedinAccess()prod-lva1
LinkedInController.linkedinAccess()X-LI-UUID
LinkedInController.linkedinAccess()zr8HGmv42hMQ9pkssyoAAA==
LinkedInController.linkedinAccess()Content-Length
LinkedInController.linkedinAccess()1
无法弄清楚问题......帮助