LeanClub icon indicating copy to clipboard operation
LeanClub copied to clipboard

Auth failed Please re-login

Open tsuibin opened this issue 10 years ago • 61 comments

在github申请了oauth id 和 Secret 填写到config.h 重新编译,测试

用github登录报错

Authorization callback URL: http://o2ee.picp.net/login/callback/github

tsuibin avatar Dec 11 '15 17:12 tsuibin

看看存储session的 redis 是否配置正确 On Sat, Dec 12, 2015 at 01:28 tsuibin [email protected] wrote:

在github申请了oauth id 和 Secret 填写到configh 重新编译,测试

用github登录报错

Authorization callback URL: http://o2eepicpnet/login/callback/github

— Reply to this email directly or view it on GitHub https://github.com/typcn/LeanClub/issues/10.

typcn avatar Dec 11 '15 17:12 typcn

检查哪一个表?

tsuibin avatar Dec 11 '15 17:12 tsuibin

redis不需要导入,config 里面 redis IP和 redis master ip填一个就可以了 On Sat, Dec 12, 2015 at 01:40 tsuibin [email protected] wrote:

检查哪一个表?

— Reply to this email directly or view it on GitHub https://github.com/typcn/LeanClub/issues/10#issuecomment-164000184.

typcn avatar Dec 11 '15 17:12 typcn

config.h里面 只有 #define REDIS_MASTER_IP "127.0.0.1" 这个配置项

tsuibin avatar Dec 11 '15 17:12 tsuibin

服务器的redis 运行状态 redis 9704 0.0 0.0 40296 3216 ? Ssl Dec10 0:39 /usr/bin/redis-server 127.0.0.1:6379

tsuibin avatar Dec 11 '15 17:12 tsuibin

redis里面是空的 tsuibin@compiler01:~$ redis-cli 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379>

tsuibin avatar Dec 11 '15 17:12 tsuibin

... ./src/redis3m/include/redis3m/connection_pool.h: * @param sentinel_port Sentinel port, default 26379 ./src/redis3m/include/redis3m/connection_pool.h: unsigned int sentinel_port=26379)

需要修改redis默认端口为26379

tsuibin avatar Dec 11 '15 17:12 tsuibin

em.. 我这里默认的 6379 没有问题啊。

Auth failed 只在这里出现了 https://github.com/typcn/LeanClub/blob/3a5c1fa007b2c909d2b751086f07783f66e8c753/src/api.cpp#L103

也就是说,POST https://github.com/login/oauth/access_token application/x-www-form-urlencoded

"client_id=" + GITHUB_OAUTH_ID +"&client_secret=" + GITHUB_OAUTH_SECRET + "&code=" + code

只有在这里失败了才会触发,你可以下个断点或者print出来github的响应内容调试一下

typcn avatar Dec 11 '15 18:12 typcn

好的,今天搞不了了,这空再调一下。

tsuibin avatar Dec 11 '15 18:12 tsuibin

params.code 打印结果 -1

tsuibin avatar Dec 14 '15 12:12 tsuibin

em... code 是 -1 的话,应该是 callback 的问题?登录 callback 之后会输出一个静态页面,然后再用一个 ajax 请求 post 你看看浏览器发上去的请求对不对 On Mon, Dec 14, 2015 at 20:39 tsuibin [email protected] wrote:

params.code 打印结果 -1

— Reply to this email directly or view it on GitHub https://github.com/typcn/LeanClub/issues/10#issuecomment-164426960.

typcn avatar Dec 15 '15 02:12 typcn

Authorization callback URL 填写是对的吗? http://o2ee.picp.net/login/callback/github

tsuibin avatar Dec 15 '15 06:12 tsuibin

对,callback 之后应该会有一个 URL 参数叫 "code" ,后面对应了一串字符,会在 ajax 请求里面传上去

typcn avatar Dec 15 '15 06:12 typcn

浏览器调试,发现这里带的参数不一样 code 应该是正确获取了

curl 'https://leanclub.org/login/callback/github?code=f3548d77764fe43db7fa&do=1&__t=1450161149170' -H 'accept-encoding: gzip, deflate, sdch' -H 'x-requested-with: XMLHttpRequest' -H 'accept-language: zh-CN,zh;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.8 Safari/537.36' -H 'accept: /' -H 'referer: https://leanclub.org/login/callback/github?code=f3548d77764fe43db7fa' -H 'authority: leanclub.org' -H 'cookie: __cfduid=d1d9a016c400e15cdf596ecc646fbde561449742683; _gat=1; cf_clearance=93dec52dbb1d4936b7c9470a239f8006c2211f95-1450160988-1800; LBSESSIONID=002OPRC8VO5W20O07V781PDMLEDOM601MFETF5T4; _ga=GA1.2.1584022163.1449742691' --compressed

curl 'http://o2ee.picp.net/login/callback/github?code=62fa869c2e036290d575&do=1&__t=1450161083466' -H 'Cookie: _gat=1; _ga=GA1.2.896167595.1450095965' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: zh-CN,zh;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.8 Safari/537.36' -H 'Accept: /' -H 'Referer: http://o2ee.picp.net/login/callback/github?code=62fa869c2e036290d575' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --compressed

tsuibin avatar Dec 15 '15 06:12 tsuibin

https://dn-leanclub-attachments.qbox.me/8225FBF27323636DF6F2933C6B7DA8F44BB810A0/14501617805206HB.png

tsuibin avatar Dec 15 '15 06:12 tsuibin

在代码里面把 params.code 和 params.body 打印出来看一下?

现在看来有可能是你的网络无法连接到 GitHub API 造成的

typcn avatar Dec 15 '15 06:12 typcn

@compiler01:~/src/LeanClub/src$ sudo ping www.github.com [sudo] password for deepin: PING github.com (192.30.252.130) 56(84) bytes of data. 64 bytes from github.com (192.30.252.130): icmp_seq=1 ttl=48 time=255 ms 64 bytes from github.com (192.30.252.130): icmp_seq=2 ttl=48 time=255 ms 64 bytes from github.com (192.30.252.130): icmp_seq=3 ttl=48 time=255 ms 64 bytes from github.com (192.30.252.130): icmp_seq=4 ttl=48 time=255 ms ^C --- github.com ping statistics --- 5 packets transmitted, 4 received, 20% packet loss, time 4004ms rtt min/avg/max/mdev = 255.351/255.646/255.980/0.452 ms

compiler01:~/src/LeanClub/build$ APP Listening on port 18080 with 500 thread(s) client_id=2df2cd6dd216d3726a72&client_secret=cbebee19c1fd7b082f4086ed1ca3a3e6f9d9e7c6&code=3b233888e5efad7d69bf params.code : -1 params.body : Failed to query.

tsuibin avatar Dec 15 '15 06:12 tsuibin

curl https://github.com/login/oauth/access_token curl https://api.github.com/user

或者是,你编译的 libcurl 没有带 HTTPS 支持或者太旧了?

typcn avatar Dec 15 '15 06:12 typcn

curl https://github.com/login/oauth/access_token {"error":"Not Found"}

curl https://api.github.com/user { "message": "Requires authentication", "documentation_url": "https://developer.github.com/v3" }

tsuibin avatar Dec 15 '15 06:12 tsuibin

wtf... 好奇怪

https://github.com/typcn/LeanClub/blob/3a5c1fa007b2c909d2b751086f07783f66e8c753/src/restclient/restclient.cpp#L247-L252

你在这里把 curl 返回的错误输出一下试试?

typcn avatar Dec 15 '15 06:12 typcn

if (res != CURLE_OK) { ret.body = "{'error':'Not Found'}"; ret.code = -1; return ret; }

改成这个样还是?

tsuibin avatar Dec 15 '15 07:12 tsuibin

不是。。把 res 输出出来

typcn avatar Dec 15 '15 07:12 typcn

@compiler01:~/src/LeanClub/build$ APP Listening on port 18080 with 500 thread(s) ret body: ret code:0

tsuibin avatar Dec 15 '15 07:12 tsuibin

https://github.com/typcn/LeanClub/blob/master/src/restclient/restclient.cpp#L246 在 res = curl_easy_perform(curl); 后面,加一行 printf('CURL ERROR: %s',curl_easy_strerror(res));

typcn avatar Dec 15 '15 07:12 typcn

compiler01:~/src/LeanClub/build$ ./leanclub APP Listening on port 18080 with 500 thread(s) CURL ERROR: Problem with the SSL CA cert (path? access rights?)client_id=2df2cd6dd216d3726a72&client_secret=cbebee19c1fd7b082f4086ed1ca3a3e6f9d9e7c6&code=a99a7308d2f723736505 -1 Failed to query.

tsuibin avatar Dec 15 '15 07:12 tsuibin

看样子是 SSL 证书错误? 尝试升级 openssl 版本,libcurl 版本,升级 ca-certs 然后重新编译试试?

或者直接把 github 的证书手动下载加入信任

typcn avatar Dec 15 '15 07:12 typcn

compiler01:~/src/LeanClub/build$ curl -V curl 7.42.1 (x86_64-pc-linux-gnu) libcurl/7.42.1 GnuTLS/3.3.15 zlib/1.2.8 libidn/1.30 libssh2/1.5.0 librtmp/2.3 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets

奇怪啊

tsuibin avatar Dec 15 '15 07:12 tsuibin

看看 /etc/pki/tls/certs/ 是否有内容? 重新安装一下 ca-certificates 试试?

typcn avatar Dec 15 '15 07:12 typcn

/etc/pki/tls/certs/ 无内容 系统安装的debian sid

tsuibin avatar Dec 15 '15 07:12 tsuibin

apt-get install ca-certificates

typcn avatar Dec 15 '15 07:12 typcn