2

I am trying to implement OAuth Stack Exchange API via Android app as client. After a successful login from out I get the below URL how do I get or decode the access_token from the hash?

https://stackoverflow.com/oauth/authorize?client_id=14702 &accountId=15559293 &scope=no_expiry &returnUrl=https%3a%2f%2fstackoverflow.com%2foauth%2fdialog%3fclient_id%3d14702%26scope%3dno_expiry%26redirect_uri%3dhttps%3a%2f%2fstackexchange.com%2foauth%2flogin_success&nonce=HDE6GdCUbq90z7Uq6l8FHg))&ticks=636889445649720585&flowKind=Implicit&hash=6d3bbaad65ce8277bc8f357d8b594d63252ba270ee0fe163b11d1cac6e5583c6 

1 Answer 1

1

Refer to the API Authentication docs; there are a great many things wrong with the URL in the question (at least 5).

For starters, it's to the wrong path. stackoverflow.com/oauth/authorize gives helpful messages/results like:

  • Oops! Something Bad Happened!

  • Authorization attempt not valid for current user

  • Authorization attempt unauthorized

  • Couldn't parse ticks (etc)

None of these messages hint at the real problems.

Anyway the correct URL per the (incorrect) docs is https://stackoverflow.com/oauth/dialog.

But it's more correct to use: https://stackexchange.com/oauth/dialog.

All the extra and redundant parameters you were passing are normally ignored (or sometimes throw an error).

The correct way to get an access token is like:
    https://stackexchange.com/oauth/dialog?client_id=14702&scope=no_expiry&redirect_uri=https://stackexchange.com/oauth/login_success
(Click it and see)


If you want to pass additional security values, they must be the state parameter.
For example, calling:

https://stackexchange.com/oauth/dialog?client_id=14702&scope=no_expiry&redirect_uri=https://stackexchange.com/oauth/login_success&state=nonce=HDE6GdCU,ticks=636889445649720585 

Note the comma-separated values.

The above call yields:

https://stackexchange.com/oauth/login_success#access_token=nUh_no_peaking_f8xkByw))&state=nonce%3dHDE6GdCU%2cticks%3d636889445649720585 

Where state decodeURIComponent decodes to: state=nonce=HDE6GdCU,ticks=636889445649720585 (the value passed in).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.