com.github.lontime.extpac4j.oauth.extractors.WechatJsonExtExtractor Maven / Gradle / Ivy
package com.github.lontime.extpac4j.oauth.extractors;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor;
import com.github.scribejava.core.model.OAuth2AccessToken;
import org.pac4j.scribe.model.WechatToken;
/**
* WechatJsonExtExtractor.
* @author lontime
* @since 1.0
*/
public class WechatJsonExtExtractor extends OAuth2AccessTokenJsonExtractor {
protected WechatJsonExtExtractor() {
}
private static class InstanceHolder {
private static final WechatJsonExtExtractor INSTANCE = new WechatJsonExtExtractor();
}
public static WechatJsonExtExtractor instance() {
return WechatJsonExtExtractor.InstanceHolder.INSTANCE;
}
@Override
protected OAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope,
JsonNode response, String rawResponse) {
String openid = extractRequiredParameter(response, "openid", rawResponse).asText();
String unionid = null;
if (response.has("unionid")) {
unionid = extractRequiredParameter(response, "unionid", rawResponse).asText();
}
WechatToken token = new WechatToken(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse, openid, unionid);
return token;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy