This page will explain how to let a user of your application subscribe to a user's private gallery. A couple of steps are required and shown below.
Implementing our SDK is easy. Include the Javascript SDK on your page once, ideally right after the <body> openingtag.
<script>(function (d, s, id) { var js, ajs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) { return; } js = d.createElement(s); js.id = id; js.src = '//cdn.adultwork.com/platform/sdk/sdk.js#APIKey={your-api-key}&clientId={your-clientid}'; ajs.parentNode.insertBefore(js, ajs); }(document, 'script', 'adultwork-jssdk'));</script>
To get an access_token with a refresh token you will have to implement the Authorization Code flow.
The refresh token can be used to get a new access token. You are responsible to get a new access token before the access token expires. The expiration is set in seconds in 'expires_in'.
Step one
Redirect the user to our Unified Login:
https://platform.AdultWork.com/OAuth/Authorize?response_type=code&client_id={your-clientId}&redirect_uri{your-redirect_uri}&state={your-state}
Step two
Receive the Authorization Code. When all authentication has been completed the Unified Login will send the code in the query string as well as the (optional) state. You can compare the state value to protect against CSRF issues.
The Unified Login will send another optional query string parameter in case the user cancels the login. This query string is called status
and will have the value of cancelled
if the user has cancelled.
Below are two examples the Unified Login could redirect the user to.
Successful
{your-redirect_uri}?code=a1b2c3d4f5&state=jau95cbrbut20isok7wd1908zp
Cancelled
{your-redirect_uri}?code=&state=jau95cbrbut20isok7wd1908zp&status=cancelled
Step three
Exchange the code for an access_token.
POST /OAuth/token HTTP/1.1 Host: platform.AdultWork.com Content-Type: application/x-www-form-urlencoded grant_type=authorization_code&client_id={your-clientid}&client_secret={your-client-secret}&code={the-received-code}&redirect_uri={your-redirect_uri}
The Unified Login will send back the access token with a refresh token. You can now make an API call with the access_token value.
An example successful response:
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Cache-Control: no-store Pragma: no-cache { "access_token":"2YotnFZFEjr1zCsicMWpAA", "token_type":"bearer", "expires_in":3600, "state": "jau95cbrbut20isok7wd1908zp", "refresh_token": "3Vtn6eOPE123Dl1JoMiQBBQC" }
Step four
Refresh the access token before it expires. You can repeat this step for the user if the user stays logged into your application.
POST /OAuth/token HTTP/1.1 Host: platform.AdultWork.com Content-Type: application/x-www-form-urlencoded grant_type=refresh_token&client_id={your-clientid}&client_secret={your-client-secret}&refresh_token={the-received-refresh_token}
Once the reference is made with our sdk as described in Implement our SDK you can call the "Buy" function quite easy.
<script> function subscribe(){ var url = 'https://platform.adultwork.com/Credits/Confirm'; var returnUri = 'https://example.com?yourreference=abc123456789'; var pricePlanId = 1; var userId = 123456; var clientId = 'A1B2C3D4E5F6'; AW.Buy.init(url, returnUri, 'gallery', pricePlanId, userId, 'en-GB', clientId); AW.Buy.confirm_window(onClose); } function onClose(){ // optional on close callback function. } </script>
Assuming the user has subscribed to the private gallery you will be able to receive the pictures and show it to the user. You have to make a call to the GetGallery method with the access token that you've got from Step Three or Step Four. You can now display the images to the user.
GET pictures/getGallery?UserID=123456 HTTP/1.1 Host: api-sandbox.adultwork.com Authorization: bearer {your-access-token}