500px / legacy-api-documentation

This is the 500px API documentation.
22 stars 9 forks source link

Unable to get accessToken by UrlCall Back in Andorid by using 500px-android-sdk #148

Open himanshumistri opened 9 years ago

himanshumistri commented 9 years ago

I am able to get request_token from OAuthAuthorization from android-sdk but here i am using my site as call back http://android-vogue.blogspot.in/ and i am able to get redirection in WebView when i open my Auth url and it's look like http://android-vogue.blogspot.in/?oauth_token=mytoken&oauth_verifier=auth_verfier key Now i am passing this Url for get accessToken .But i am getting below Error:

Here is my Auth 1.0 Request :

OAuth oauth_callback="http://android-vogue.blogspot.in/?oauth_token=hULQrDHjDGVZcCt8IyEIuivxcOeagdWhI0KGjePS&oauth_verifier=GXN6d3ZK625GqgRjWvl3http%3A%2F%2Fandroid-vogue.blogspot.in%2F%3Foauth_token%3DhULQrDHjDGVZcCt8IyEIuivxcOeagdWhI0KGjePS%26oauth_verifier%3DGXN6d3ZK625GqgRjWvl3", oauth_consumer_key="Key", oauth_nonce="1434714669", oauth_signature="9l9XZpe2y32RePKDOpT66qXym0U%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1434714666", oauth_token="hULQrDHjDGVZcCt8IyEIuivxcOeagdWhI0KGjePS", oauth_version="1.0"

photos W/DefaultRequestDirector﹕ Authentication error: Unable to respond to any of these challenges: {} 06-19 07:19:31.090 27726-27928/com.xxxxx.fivephotos W/System.err﹕ com.fivehundredpx.api.FiveHundredException 06-19 07:19:31.091 27726-27928/com.xxxx.fivephotos W/System.err﹕ at com.fivehundredpx.api.auth.OAuthAuthorization.getAccessToken(OAuthAuthorization.java:122)

CoryCharlton commented 9 years ago

Never used the Android SDK so maybe I'm misunderstanding but it doesn't look like you are passing the oauth_verifier in the authorization parameters.

Here's how my application's authentication flow looks like (note the oauth_callback never changes):

Request token:

https://api.500px.com/v1/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost%3A43298%2FOAuth%2F&oauth_consumer_key=[CONSUMER_KEY]&oauth_nonce=6300507&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1435005512&oauth_version=1.0&oauth_signature=oa%2B1GR%2FVCD2J5Hu%2BhzjzoPgQFz0%3D

Authorize request token:

https://api.500px.com/v1/oauth/authorize?oauth_callback=http%3A%2F%2Flocalhost%3A43298%2FOAuth%2F&oauth_consumer_key=[CONSUMER_KEY]&oauth_nonce=4176981&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1435005513&oauth_token=[REQUEST_TOKEN]&oauth_version=1.0&oauth_signature=iCS%2F0fto8EsAQgxI7abAFydYx8U%3D

Exchange request token + verifier for an access token:

https://api.500px.com/v1/oauth/access_token?oauth_callback=http%3A%2F%2Flocalhost%3A43298%2FOAuth%2F&oauth_consumer_key=[CONSUMER_KEY]&oauth_nonce=1954385&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1435005526&oauth_token=[REQUEST_TOKEN]&oauth_verifier=[VERIFIER]&oauth_version=1.0&oauth_signature=A2MKtkjkRH%2FJTKp6NtbBHXs8dDw%3D

Use the access token for an authenticated request:

https://api.500px.com/v1/users?oauth_callback=http%3A%2F%2Flocalhost%3A43298%2FOAuth%2F&oauth_consumer_key=[CONSUMER_KEY]&oauth_nonce=3076801&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1435005526&oauth_token=[ACCESS_TOKEN]&oauth_version=1.0&oauth_signature=QEH44ZBFK3FyuzZvWtP%2FL8MDWbc%3D

Hope this helps :)

luojun commented 9 years ago

Hi @Himanshu4003,

It looks like you are attempting an OAuth flow that's not supported by the Android SDK.

Please take a look at the documentation here: https://github.com/500px/api-documentation/blob/master/authentication/POST_oauth_accesstoken.md. The 500px Android SDK supports the xAuth workflow. To see how it works with Facebook and Google, you can see here: https://github.com/500px/500px-android-sdk/blob/master/src/main/java/com/fivehundredpx/api/auth/FacebookAuthProvider.java and here: https://github.com/500px/500px-android-sdk/blob/master/src/main/java/com/fivehundredpx/api/auth/PlusAuthProvider.java, wherein the Facebook token and Plus Token were respectively obtained from Facebook and Google's corresponding service for the user.

himanshumistri commented 9 years ago

Hi @machx0r Thanks for your input on Auth Flow now i understand it's correctly and it's working fine.