curl -X POST -H "Authorization: Client-ID $client_id" -H "Content-Type: application/json; charset=utf-8" https://api.imgur.com/oauth2/token -d "{"refresh_token":"$authorization_code","client_id":"$client_id","client_secret":"$client_secret","grant_type":"refresh_token"}"
I get this as the response:
{"data":{"access_token":null,"expires":-1355617767,"account_username":null},"success":true,"status":200}
It seems to be a successful response, but the access token and username are null, and the expires doesn't quite seem right.
Am I missing something? I can't use the authorization code itself as a Bearer token (I get 403s).
Thanks,
Stephen
It would be helpful to have more documentation around the OAuth 2 endpoints in general. An example for the /oauth2/token endpoint, for one, and more information around using /oauth2/addclient and /oauth2/secret.
I will also go in and verify everything is working and add some better error handling to prevent this in future.
~Josh
It doesn't identify whether it's a refresh_token, access_token, or otherwise. When I attempt to use it as a refresh token, I get the response I posted earlier. When I attempt to use it as an access token, I get 403s.
I actually get a 500 error when I try using POST parameters:
curl -X POST -H "Authorization: Client-ID $client_id" -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" -H "Accept-Language: en, ja, fr, de, es, it, pt, pt-PT, nl, sv, nb, da, fi, ru, pl, zh-Hans, zh-Hant, ko, ar, cs, hu, tr, th, ca, hr, el, he, ro, sk, uk, en-us" "https://api.imgur.com/oauth2/token" -d "refresh_token=$refresh_token" -d "client_id=$client_id" -d "client_secret=$client_secret" -d "grant_type=refresh_token"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> imgur: the simple error page</title>
...
Same thing if I explicitly use "Accept: application/json; charset=utf-8"
The callback I get on my end only has the following parameter in the query string, e.g.:
?code=76388bc19b1905a402c16e9baf782cbe8b257c7f
Can't this be used as a refresh token? What am I supposed to do with a "code" that I request with "response_type=code"?
Thanks,
Stephen
Thanks again,
Stephen
Can you please also clarify my earlier question?:
How do I verify that refresh_token is a refresh token? The callback I get on my end only has the following parameter in the query string, e.g.:
?code=76388bc19b1905a402c16e9baf782cbe8b257c7f
Can't this be used as a refresh token? What am I supposed to do with a "code" that I request with "response_type=code"?
Thanks!
Even the GET request to /oauth2/token seems to be failing for me:
~ % curl -H "Authorization: Bearer $code" https://api.imgur.com/oauth2/token
{"data":{"access_token":null,"expires":-1355862122,"account_username":null},"success":true,"status":200}
https://example.com/oauthcallback?code=AUTHORIZATION_CODE
Wherein "AUTHORIZATION_CODE" is the label, not ACCESS_TOKEN.
(Meanwhile you use ACCESS_TOKEN in your JavaScript Responses example.)
http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.3
Will take some testing, but I think I finally have it.
It's a bummer that access tokens we get via authorization code expire (adds an extra layer of complexity that wasn't there with OAuth 1). I assume the refresh token changes every time I fetch a new access token, and that I'll have to re-save the refresh token every time?
The security concern is at the access token level because acquiring a new access token requires the client_id, client_secret, and refresh_token/authorization_code. Because of this, a malicious third party cannot intercept the access_token and use it indefinitely. If a malicious third party were to intercept a refresh_token, they would not be able to get an access token unless they also managed to intercept the client_id and client_secret.
Consider my example:
I have a desktop application that used to store the OAuth 1 access token securely in the OS X login keychain. I can no longer do this with your OAuth 2 integration because you expire your access tokens. I can, however, store the refresh token and fetch access tokens as needed (updating the refresh_token as I go if need be). If an unused refresh token expires after a time limit, though, then I will have to make my users re-authorize regularly, a step that I should be able to avoid (securely, using the refresh token). I'd really like to make sure the user experience doesn't degrade.
Can I request that unused refresh tokens do not expire? If they do expire, what's the TTL? I'd hope at least a few days (I don't want an app user to go to sleep, wake up, and have to re-auth every morning they use my app).
Thanks,
Stephen
{"access_token":"d9e86dbb43df4c9********c80dfc31aed6f1669","expires_in":3600,"token_type":"bearer","scope":null,"refresh_token":"16a762837b6*********173212893c7c9fb84"}
12-19 09:57:59.353: INFO/ActivityManager(150): START {act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=*********-imgur://callback?code=c4dafbc1d844922cb428********* flg=0x3000000 cmp=com.v3.playground/.LoginActivity (has extras) u=0} from pid 150
12-19 09:57:59.733: DEBUG/*********.HttpConnection(1407): posting url encoded entity grant_type=authorization_code&code=c4dafbc1d844922cb428*********&redirect_url=*********-imgur%3A%2F%2Fcallback&client_id=b86d*********
12-19 09:57:59.733: DEBUG/*********.HttpConnection(1407): Making HTTP POST request to https://api.imgur.com/oauth2/token
12-19 09:57:59.833: DEBUG/*********.HttpConnection(1407): with header: Content-Type=application/x-www-form-urlencoded
12-19 09:57:59.833: DEBUG/*********.HttpConnection(1407): with header: Authorization=Client-ID b86d*********
12-19 09:58:00.443: DEBUG/*********.HttpConnection(1407): Response JSON: {"access_token":"7c3df1b030e1d60d7e8e8*********","expires_in":3600,"token_type":"bearer","scope":null,"refresh_token":"69ced1fca0f13d5a631cd0*********"}
12-19 09:58:00.643: DEBUG/*********(1407): token recieved! 7c3df1b030e1d60d7e8e8f50*********
12-19 10:00:52.723: INFO/ActivityManager(150): START {act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=*********-imgur://callback?code=0123bda1a21714b3aa3f4********* flg=0x3000000 cmp=com.v3.playground/.LoginActivity (has extras) u=0} from pid 150
12-19 10:00:53.093: DEBUG/*********.HttpConnection(1476): posting url encoded entity grant_type=authorization_code&code=0123bda1a21714b3aa3f47dc*********&redirect_url=*********-imgur%3A%2F%2Fcallback&client_id=b86d30*********
12-19 10:00:53.125: DEBUG/*********.HttpConnection(1476): Making HTTP POST request to https://api.imgur.com/oauth2/token
12-19 10:00:53.183: DEBUG/*********.HttpConnection(1476): with header: Content-Type=application/x-www-form-urlencoded
12-19 10:00:53.183: DEBUG/*********.HttpConnection(1476): with header: Authorization=Client-ID b86d3*********
12-19 10:00:53.813: DEBUG/*********.HttpConnection(1476): Response JSON: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> .....the remaining content is html error page.
Is there and error code on the HTML error page? That would help us track it down in the logs.
<div id="text-content">
<h1>Error (0)</h1>
<div class="textbox bigtext">
Sorry! There was an error (code: <span class="green">0</span>)
retrieving the page you requested. Try refreshing or double checking
your URL. If you think this error is an error, try
<a href="http://imgur.com/contact">contacting us</a> about it.
</div>
</div>
After reading this article: http://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified ..
Your application can choose to have the authorization code returned in the title of the web page or to ahttp://localhost
port. Once the application receives the authorization code, it can exchange the code for an access token and a refresh token.