Skip to content

Commit

Permalink
fix authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanPopenko committed May 10, 2016
1 parent 8d77197 commit f73c1d2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions docs/api/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ client_secret (= '{yourClientSecret}')
redirect_uri (= '{redirectUrl}') - the same as in step 1
grant_type = (= 'authorization_code')

This necessary if you want receive token on server side (see Java example).

If you want receive token in client side you need send client_id and client_secret in header of request.
It's attached as parameter:
Authorization (="Basic " + ConvertBase64Encoding(client_id + ":" + client_secret)).
See JS example.

As response to the redirect_uri you will receive json object with next properties:

access_token (token for access to API)
refresh_token (when token is expired, you can exchange refresh_token to new access_token, see step 3)
expires_in (date and time until token is suitable to getting access)
expires_in (property is a number of seconds after which the access token expires, and is no longer valid)

access_token object has another properties, but trey aren't necessary for accessing to API.


Code example **Java** using org.apache.http package

.. code-block:: properties
Expand Down Expand Up @@ -106,22 +114,24 @@ Code example **JS** using JQuery
var redirectURI = "{redirectUrl}";
var clientId = "{yourClientId}";
var clientSecret = "{yourClientSecret}";
var base64IdAndSecret = btoa(clientId + ':' + clientSecret);//IE 10 and higher
var code = location.href.split('code=')[1];//get value of parameter code
// it's only one param, so you can use this way to get code, or write your own
$.post({
url : tokenURI,
data : {
'code' : code,
'client_id' : clientId,
'client_secret' : clientSecret,
'redirect_uri' : redirectURI,
'grant_type' : 'authorization_code'
},
beforeSend : function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + base64IdAndSecret);
},
success : function (token) {
alert(token['access_token']); //use received token
alert(token['refresh_token']);
alert(token['expires_in']);
alert(token['access_token']); //use received token
alert(token['refresh_token']);
alert(token['expires_in']);
}
});
Expand Down

0 comments on commit f73c1d2

Please sign in to comment.