use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.
the class WechatOauthComponent method getAuthorizeUrl.
/*
*
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=
* resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN
*
*/
public String getAuthorizeUrl(short siteId, String state, boolean mobile) {
OauthConfig config = getConfig(siteId);
if (null != config) {
StringBuilder sb = new StringBuilder("https://open.weixin.qq.com/connect/qrconnect?appid=");
sb.append(config.getAppKey()).append("&redirect_uri=").append(config.getReturnUrl()).append("&response_type=code&scope=snsapi_login&state=").append(state).append("#wechat_redirect");
return sb.toString();
}
return null;
}
use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.
the class WeiboOauthComponent method getAccessToken.
/**
* http://open.weibo.com/wiki/Oauth2/access_token
*/
@Override
public OauthAccess getAccessToken(short siteId, String code) throws ClientProtocolException, IOException {
OauthConfig config = getConfig(siteId);
if (CommonUtils.notEmpty(code) && null != config) {
Map<String, String> paramters = new HashMap<>();
paramters.put("client_id", config.getAppKey());
paramters.put("client_secret", config.getAppSecret());
paramters.put("grant_type", "authorization_code");
paramters.put("redirect_uri", config.getReturnUrl());
paramters.put("code", code);
String html = post("https://api.weibo.com/oauth2/access_token", paramters);
if (CommonUtils.notEmpty(html)) {
Map<String, Object> map = objectMapper.readValue(html, new TypeReference<Map<String, Object>>() {
});
return new OauthAccess(code, (String) map.get("access_token"), String.valueOf((Integer) map.get("uid")));
}
}
return null;
}
use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.
the class AbstractOauth method getConfig.
/**
* @param siteId
* @return
*/
protected OauthConfig getConfig(short siteId) {
Map<String, String> config = configComponent.getConfigData(siteId, CONFIG_CODE);
OauthConfig oauthConfig = new OauthConfig(config.get(prefix + CONFIG_APP_KEY), config.get(prefix + CONFIG_APP_SECRET), config.get(prefix + CONFIG_RETURN_URL));
if (CommonUtils.notEmpty(config) && CommonUtils.notEmpty(oauthConfig.getAppKey()) && CommonUtils.notEmpty(oauthConfig.getAppSecret()) && CommonUtils.notEmpty(oauthConfig.getReturnUrl())) {
return oauthConfig;
}
return null;
}
use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.
the class QQOauthComponent method getAuthorizeUrl.
/*
* http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%
* E5%8F%96access_token
*/
@Override
public String getAuthorizeUrl(short siteId, String state, boolean mobile) {
OauthConfig config = getConfig(siteId);
if (null != config) {
StringBuilder sb = new StringBuilder("https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=");
sb.append(config.getAppKey()).append("&redirect_uri=").append(config.getReturnUrl()).append("&scope=get_user_info").append("&state=").append(state);
if (mobile) {
sb.append("&display=mobile");
}
return sb.toString();
}
return null;
}
use of com.publiccms.view.pojo.oauth.OauthConfig in project PublicCMS-preview by sanluan.
the class QQOauthComponent method getAccessToken.
@Override
public OauthAccess getAccessToken(short siteId, String code) throws ClientProtocolException, IOException {
OauthConfig config = getConfig(siteId);
if (CommonUtils.notEmpty(code) && null != config) {
StringBuilder sb = new StringBuilder("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&code=");
sb.append(code).append("&client_id=").append(config.getAppKey()).append("&client_secret=").append(config.getAppSecret()).append("&redirect_uri=").append(config.getReturnUrl());
String html = get(sb.toString());
if (CommonUtils.notEmpty(html)) {
String[] values = html.split("&");
for (String value : values) {
if (value.startsWith("access_token=")) {
return new OauthAccess(code, value.split("=")[1]);
}
}
}
}
return null;
}
Aggregations