Skip to content

Commit 17317d8

Browse files
authored
Merge pull request #186 from inplayer-org/docs-2124-2127-authenticate-users
Create authenticate-and-authorize-users.md
2 parents 8370776 + a6ca493 commit 17317d8

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
id: authenticate-and-authorize-users
3+
title: Authenticate and authorize users
4+
slug: /authenticate-and-authorize-users
5+
---
6+
Your video content is valuable and only authorized users should be permitted to view it. When a user launches your app, your app must identify the user and the content available to the user. JWP enables you to both identify users and manage their access to your content.
7+
8+
<br />
9+
10+
## Prerequisites
11+
12+
<table>
13+
<thead>
14+
<tr>
15+
<th>Item</th>
16+
<th>Description</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td><strong>Existing app</strong></td>
22+
<td><a href="https://docs.jwplayer.com/platform/docs/apps-get-started" target="_blank">App</a> connected to a JWP property
23+
<br /><br />
24+
The app can also be enabled for <a href="https://developers.inplayer.com/docs/enable-web-payments-with-stripe/" target="_blank">web</a> and <a href="https://developers.inplayer.com/docs/enable-third-party-platform-payments" target="_blank">third-party</a> payments.
25+
</td>
26+
</tr>
27+
<tr>
28+
<td><strong>Asset ID</strong> & <strong>Client ID</strong></td>
29+
<td>IDs that enable access to content when combined:
30+
<ul>
31+
<li><strong>Asset ID</strong>: Subscription asset that must be purchased to watch content on the app</li>
32+
<li><strong>Client ID</strong>: Authentication realm where user account is created</li>
33+
</ul>
34+
<em>Contact your JWP representative for more information.</em>
35+
</td>
36+
</tr>
37+
</tbody>
38+
</table>
39+
40+
<br />
41+
42+
## Set user authentication and authorization
43+
44+
<br />
45+
46+
Follow these steps to enable authentication and authorization for an existing user:
47+
48+
1. Log in an existing user account by calling [`POST /v2/accounts/authenticate`](https://docs.inplayer.com/api/accounts/#tag/V2/operation/v2authenticate) (REST API) or [`InPlayer.Account.signIn()`](https://inplayer-js.netlify.app/classes/account___authentication.account#signInV2) (JavaScript).
49+
50+
When the request **succeeds**, JWP returns a unique user authentication token. When the request **fails**, JWP returns a failure response.
51+
52+
**REST API**
53+
```cURL
54+
curl -L -X POST 'https://services.inplayer.com/v2/accounts/authenticate' \
55+
-H 'Content-Type: application/x-www-form-urlencoded' \
56+
--data-urlencode 'username=test@test.com' \
57+
--data-urlencode 'password=test123' \
58+
--data-urlencode 'grant_type=password' \
59+
--data-urlencode 'client_id=123-123-hf1hd1-12dhd1' \
60+
```
61+
62+
**JavaScript**
63+
```javascript
64+
InPlayer.Account.signInV2({
65+
email: 'test@test.com',
66+
password: 'test123',
67+
cliendId: '123-123-hf1hd1-12dhd1',
68+
referrer: 'http://localhost:3000/'
69+
})
70+
.then(data => console.log(data));
71+
```
72+
2. Validate the user's access by calling `GET /v2/items/jw-media/token?app_config_id={appConfigId}&media_id={mediaId}` (REST API) or [`checkAccessForAsset()`](https://inplayer-js.netlify.app/classes/asset___access.asset#checkAccessForAsset) (Javascript).
73+
74+
If access to the asset **is verified**, the method returns the content in the response that you can display in your app. If access to the asset **cannot be verified**, your app should redirect the user to your payment page to re-enter payment details.
75+
76+
**REST API**
77+
```cURL
78+
curl https://services.inplayer.com/v2/items/jw-media/token?app_config_id={appConfigId}&media_id={mediaId} \
79+
-H "Authorization:Bearer <token>"
80+
```
81+
82+
**JavaScript**
83+
```javascript
84+
InPlayer.Asset
85+
.checkAccessForAsset(InPlayer.Account.token(),ASSET_ID)
86+
.then(data => console.log(data))
87+
.catch(error => error.response.json().then(data => console.log("Error", data)));
88+
89+
```
90+
91+
<br/>
92+
93+
After you have validated the user's access, you can fetch the content by media ID and begin playback.
94+
95+
If you use an app config to manage your content, you can obtain the media ID from the `contentId` parameter of the app config URL.
96+
97+
:::tip
98+
You can add <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#url-signing-for-apps" target="_blank">URL signing</a> or <a href="https://docs.jwplayer.com/platform/docs/enable-protection-apps#drm" target="_blank">digital rights management (DRM)</a> for extra layers of content protection.
99+
:::

sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
'guides/page-protection',
4545
'guides/enable-third-party-platform-payments',
4646
'guides/enable-web-payments-with-stripe',
47+
'guides/authenticate-and-authorize-users',
4748
{
4849
type: 'category',
4950
label: 'Standalone Services',

0 commit comments

Comments
 (0)