1 Star 0 Fork 216

yiane / jfinal-oauth2.0-login

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

##对第三方登陆的基础封装 集成qqsinabaidurenrenosc豆瓣 等,第三方登陆api!

并非只有jfinal中可以使用

也可用户其他构架中!具体可参看Test.java测试

注意 ·oauth.properties· 中含有我的网站的appkey可用来测试

测试时先更改hosts(具体可以google

127.0.0.1 www.dreamlu.net

测试过程为

  1. 调用getAuthorizeUrl()获取url,在浏览器访问url,拿到回调的code参数

  2. 调用getUserInfoByCode()传入刚获取的code

有不明白的可以联系本人,QQ:596392912

JFinal 中使用示例

跳转去授权

//OAuth2.0标准协议建议,利用state参数来防止CSRF攻击。可存储于session或其他cache中
private static final String SESSION_STATE = "_SESSION_STATE_QQ_";

/**
 * 构造授权请求url
 * @param     设定文件
 * @return void    返回类型
 * @throws
 */
public void index() {
    try {
        String state = TokenUtil.randomState();
        setSessionAttr(SESSION_STATE, state);
        redirect(OauthQQ.me().getAuthorizeUrl(state));
    } catch (Exception e) {
        log.error(e.getMessage());
        redirect("/");
    }
}

回调可供参考

/**
 * 腾讯回调
 * @Title: callback
 * @param     设定文件
 * @return void    返回类型
 * @throws
 * 返回json:<url>http://wiki.connect.qq.com/get_user_info</url>
 */
public void callback() {
    String code = getPara("code");
    String state = getPara("state");
    String session_state = getSessionAttr(SESSION_STATE);
    // 取消了授权
    if (StringKit.isBlank(state) || StringKit.isBlank(session_state) || !state.equals(session_state) || StringKit.isBlank(code)) {
        redirect("/admin");
        return;
    }
    removeSessionAttr(SESSION_STATE);
    try{
        JSONObject userInfo = OauthQQ.me().getUserInfoByCode(code);
        log.error(userInfo);
        String type = "qq";
        String openid = userInfo.getString("openid");
        String nickname = userInfo.getString("nickname");
        String photoUrl = userInfo.getString("figureurl_2");
        // 将相关信息存储数据库...
    }catch(Exception e){
        log.error(e);
    }
    redirect("/admin");
}

注意事项

申请期间可以添加测试账号

为了快速的申请通过,请使用QQ官方的最大的那个(图标素材)

The MIT License (MIT) Copyright (c) 2014 孤独的3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

oauth2.0第三方 qq、sina、baidu、renren、osc、豆瓣 等,登陆的简易封装! expand collapse
MIT
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
1
https://gitee.com/yiane/jfinal-oauth2.0-login.git
git@gitee.com:yiane/jfinal-oauth2.0-login.git
yiane
jfinal-oauth2.0-login
jfinal-oauth2.0-login
master

Search