Subscribe to gallery

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.

  1. Implement our SDK.
  2. Get an access_token using the Authorization Code login flow.
  3. Call the "Buy" function in our SDK.
  4. Make the API call on behalf of the user.

 

 

Implement our SDK

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>
  • {your-api-key}
    • The api key of your project. This can be found in the project's details page.
  • {your-clientid}
    • The client identifier. This can be found in the project's details page under the Unified Login tab.

 

 

Get an access_token using the Authorization Code login flow

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}
  • response_type
    • The value must be set to "code".
  • client_id
    • The client identifier. This can be found in the project's details page under the Unified Login tab.
  • redirect_uri
    • The absolute URI to which the Unified Login will send the code.
  • scope
    • The scope of the requested permissions. The Unified Login requires at least the scope userid.
  • state
    • This is a value used by the client to maintain state between the request and callback. The Unified Login includes this value when redirecting the user-agent back to the client. You can use this to protect against CSRF issues.

 

 

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}
  • grant_type
    • The value must be set to "authorization_code" to exchange the code for an access token.
  • client_id
    • The client identifier. This can be found in the project's details page under the Unified Login tab.
  • client_secret
    • The client secret. This can be found in the project's details page under the Unified Login tab.
  • code
    • This is the code received from the Unified Login.
  • redirect_uri
    • The absolute URI to which the Unified Login will send the code.
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}
  • refresh_token
    • The value must be set to "refresh_token" to get a new access token with a refresh token.
  • client_id
    • The client identifier. This can be found in the project's details page under the Unified Login tab.
  • client_secret
    • The client secret. This can be found in the project's details page under the Unified Login tab.
  • refresh_token
    • This is the refresh token received from the Unified Login. Use this to obtain a new token.

 

 

Call the "Buy" function in our SDK.

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>
  • url
    • The URL of our buy functionality in the platform. This value must be set to 'https://platform.adultwork.com/Credits/Confirm'.
  • returnUri
    • The sdk will open a pop-up. You can choose to let the pop-up set the URI of the opener (your page). For example you can refresh the current page. If you don't want to use this parameter send in a empty string ('').
  • pricePlanId
  • userId
    • The user id of the owner of the gallery.
  • clientId
    • The client identifier. This can be found in the project's details page under the Unified Login tab.
  • onClose
    • Optional callback function which the SDK will call when the pop-up closes.

 

 

Make the API call on behalf of the user.

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}