1 Star 1 Fork 216

Javen / JFinal-oauth2.0-login

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

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

具体可参看Test.java测试,该版本已经深度依赖于JFinal,对于非JFinal用户,可以查看 tag v0.2: http://git.oschina.net/596392912/JFinal-oauth2.0-login/tree/v0.2/

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

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

127.0.0.1 www.dreamlu.net

测试过程为

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

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

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");
}

Maven

<dependency>
    <groupId>net.dreamlu</groupId>
    <artifactId>JFinal-oauth2.0-login</artifactId>
    <version>1.1.1</version>
</dependency>

jar包依赖

  1. FastJson

  2. JFinal3.0

注意事项

申请期间可以添加测试账号,为了快速的申请通过,请使用QQ官方的最大的那个(图标素材)

交流群

JFinal2.2视频-如梦技术 237587118

捐助共勉

微信捐助 支付宝捐助 QQ捐助

License

( The MIT License )

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、豆瓣 等,登陆的简易封装! 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助