WeiboJsonExtractor extends OAuth2AccessTokenJsonExtractor { @Override protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, JsonNode response, String rawResponse) { OAuth2AccessToken token = super.createToken(accessToken, tokenType, expiresIn, refreshToken, scope, response, rawResponse); String uid = extractRequiredParameter(response, "uid", rawResponse).asText(); if (uid == null || "".equals(uid)) { throw new OAuthException( "There is no required UID in the response of the AssessToken endpoint."); } return new WeiboToken(token, uid); }  static WeiboJsonExtractor instance();  }
@Test public void createTokenHasUid() throws IOException { OAuth2AccessToken accessToken = extractor.createToken("ACCESS_TOKEN", null, 123, null, null, mapper.readTree(responseOk), responseOk); Assert.assertEquals("ACCESS_TOKEN", accessToken.getAccessToken()); assertTrue(accessToken instanceof WeiboToken); if (accessToken instanceof WeiboToken) { Assert.assertEquals("12341234", ((WeiboToken) accessToken).getUid()); } }
@Test(expected = OAuthException.class) public void createTokenWithOutUid() throws IOException { extractor.createToken("ACCESS_TOKEN", null, 123, null, null, mapper.readTree(responseError), responseError); }