OAuth2AccessTokenResponse extends OAuthAccessTokenResponse { protected void setBody(String body) throws OAuthProblemException { try { this.body = body; parameters = JSONUtils.parseJSON(body); } catch (JSONException e) { if (body.startsWith("#")) { body = body.substring(1); } parameters = OAuthUtils.decodeForm(body); if (StringUtils.isNullOrEmpty(getAccessToken())) { throw OAuthProblemException.error(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE, "Invalid response! Response body is not " + OAuth.ContentType.JSON + " encoded or form-url-encoded"); } } }  @Override String getAccessToken(); @Override Long getExpiresIn(); String getScope(); OAuthToken getOAuthToken(); String getRefreshToken();  }
@Test public void readsTokenFromJSONBody() throws OAuthProblemException { String jsonBody = "{\n" + " \"access_token\" : \"" + DUMMY_ACCESS_TOKEN + "\",\n" + " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : " + EXPIRES_IN + ",\n" + " \"refresh_token\" : \"" + DUMMY_REFRESH_TOKEN + "\"\n" + "}"; tokenResponse.setBody(jsonBody); assertTokenResponseParameters(tokenResponse); }
@Test public void readsTokenFromFormURLEncodedBody() throws OAuthProblemException { tokenResponse.setBody(getFormUrlEncodedresponseBody()); assertTokenResponseParameters(tokenResponse); }
@Test public void readsTokenFromFormURLEncodedBodyWithHash() throws OAuthProblemException { tokenResponse.setBody("#" + getFormUrlEncodedresponseBody()); assertTokenResponseParameters(tokenResponse); }