itchyny / calendar.vim

A calendar application for Vim
MIT License
1.95k stars 72 forks source link

[calendar] Fail in authorization to Google #154

Closed gzqx closed 4 years ago

gzqx commented 4 years ago

Problem I have

let g:calendar_google_calendar = 1

in my vimrc, and get [calendar] Fail in authorization to Google after pasted the requested code. I have tried to remove all files in ~/.cache/calendar.vim/

Environment Information

itchyny commented 4 years ago

Please run with :Calendar -debug and check the response in ~/.cache/calendar.vim/download/.

gzqx commented 4 years ago

It is empty

itchyny commented 4 years ago

You mean empty response? Or empty directory?

gzqx commented 4 years ago

empty directory.

itchyny commented 4 years ago

Hmm, the message Fail in authorization to Google is shown after a http request to the api and there should be some response file. Can you test with let g:calendar_debug = 1 again? Or you configure g:calendar_cache_directory?

purefun commented 4 years ago

I can reproduce this issue. I think the key is the proxy, but I can't tell what's the problem with the proxy.

After inserting a line echom string(response.content) between L62-L63 https://github.com/itchyny/calendar.vim/blob/644f88b9ddb17ef04c4558e945d1995aab400a96/autoload/calendar/google/client.vim#L57-L63

Fail in authorization to Google result is:

'^M^@HTTP/2 200 ^M^@content-type: application/json; charset=utf-8^M^@vary: X-Origin^M^@vary: Referer^M^@vary: Origin,Accept-Encoding^M^@date: Thu, 28 Nov 2019 15:26:01 GMT^M^@serve
r: ESF^M^@cache-control: private^M^@x-xss-protection: 0^M^@x-frame-options: SAMEORIGIN^M^@x-content-type-options: nosniff^M^@accept-ranges: none^M^@^M^@{^@  "access_token": "ya29.I
l-zB7Ld3a6o6E0ub5O_HqLOuD5KPz_n4EGcLQx2a8zM-2mhzTgCpHAU7i2R1hVmKMiznayIRAFgvR8tRAmdP8RG1l7FlUmytLGcUmTgVhUBnSY9ZC1dSE_lkE68e-Oq7g",^@  "expires_in": 3600,^@  "refresh_token": "1//0
eBfBnwNGtjtaCgYIARAAGA4SNwF-L9IrF_U5u2ks2qfUSzc6fiPqVsf1jl6_GRmaVh4vepgEuLJa2rzxslVE-D-3iVtmu86O7do",^@  "scope": "https://www.googleapis.com/auth/calendar https://www.googleapis.c
om/auth/tasks",^@  "token_type": "Bearer"^@}'
shot-1

authorize successfully:

CODE: 4/twHXe1rdhwP9a0OSwUfYtK4lhKNfTnU52qcS3BP2l7Ye6H3QOgFLAqY'^M^@{^@  "access_token": "ya29.Il-zB4XtOgQ1X-ZUhb1rHmJTOZl0HexQ1zOFDb1BeFjiF0jdl9E2XNOF7LQsg46OxSOm0rrLWEHFgtlkuXDkG
fochZjDcZmazMziZy02zsO4fC20ggRHTxhAg9woLnnaWg",^@  "expires_in": 3600,^@  "refresh_token": "1//0eG6dfdNTD4qzCgYIARAAGA4SNwF-L9IrwSfPYdXNbLB0jNCFlk3LIhXfk7Tg3bsLhQeYU8MGVwtMd35iFf7Q
yOW6r27ykG43HVw",^@  "scope": "https://www.googleapis.com/auth/tasks https://www.googleapis.com/auth/calendar",^@  "token_type": "Bearer"^@}'
shot-2
itchyny commented 4 years ago

Oh, proxy problem #111. So HTTPS_PROXY does not work? Adding -x ... option in s:command in webapi.vim solves the issue?

purefun commented 4 years ago

HTTPS_PROXY is OK. the failed response.content has access_token, but the response json schema is not the same. Later on I'm going to echo s:command and execute it manually.

Thank you for your response.

purefun commented 4 years ago

I found the problem about my proxy. It can't handle curl with http2 very well.

If I add the option --http1.1 to curl, it works good.

curl --http1.1 -k -i -N -X POST -H "Content-Length: 265" --data-binary @"urlencoded-form" "https://accounts.google.com/o/oauth2/token"
itchyny commented 4 years ago

Thanks for information, I added the --http1.1 flag for now (in my environment HTTP/2 also works but there's no reason to stick to HTTP/2).

purefun commented 4 years ago

Thanks a lot.

gzqx commented 4 years ago

The problem is solved and thanks a lot.

purefun commented 4 years ago

@guzhaqixin May using socks5 protocol proxy instead of http, if you run into 401 invalid credentials. cause http proxy wraps http status code, curl never gets remote server 401 code.

https://github.com/itchyny/calendar.vim/blob/ff2149d6f022ffdd51c1fa5dbf9b653800f2298b/autoload/calendar/google/calendar.vim#L49

curl https://ip.gs/404 -i -x http://localhost:6152

note the first line:

HTTP/1.0 200 Connection established

HTTP/2 404
date: Fri, 29 Nov 2019 11:15:58 GMT
content-type: text/html
set-cookie: __cfduid=ded4da53b6e72ac1dce2878a0994360901575026158; expires=Sun, 29-Dec-19 11:15:58 GMT; path=/; domain=.ip.gs; HttpOnly
vary: Accept-Encoding
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 53d42aaf1eb6463c-TPE

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

curl https://ip.gs/404 -i -x socks5://localhost:6153

HTTP/2 404
date: Fri, 29 Nov 2019 11:16:10 GMT
content-type: text/html
set-cookie: __cfduid=dd0ff3b64fd8498932b46af06d649650f1575026170; expires=Sun, 29-Dec-19 11:16:10 GMT; path=/; domain=.ip.gs; HttpOnly
vary: Accept-Encoding
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 53d42afbdbe64642-TPE

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>