0 Star 0 Fork 216

divenswu / jfinal-oauth2.0-login

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
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.

简介

oauth2.0第三方 qq、sina、baidu、renren、osc、豆瓣 等,登陆的简易封装! 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/divenswu/jfinal-oauth2.0-login.git
git@gitee.com:divenswu/jfinal-oauth2.0-login.git
divenswu
jfinal-oauth2.0-login
jfinal-oauth2.0-login
master

搜索帮助