Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions docs/core-concepts/authorization-authentication/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords:
- deriv-authorization
description: deriv api authentication and authorization
---

Without authentication and authorization you'll only get access to roughly half of our API calls and features. for example in order to buy contracts or utilize the `Copy Trading` features your users must be authenticated and authorized by our **OAuth** provider and **Websocket Server**.

## Before we start
Expand All @@ -20,12 +21,12 @@ You have to make sure you have all the requirements mentioned bellow to continue

### Requirements

1. Deriv Account
1. Deriv Account
2. Deriv API Token with the appropriate access level
3. Deriv App ID
3. Deriv App ID

:::note
Please refer to [Setting up a Deriv Application](docs/setting-up-a-deriv-application) for detailed instruction how to create Deriv API token and Applications
Please refer to [Setting up a Deriv Application](/docs/setting-up-a-deriv-application.md) for detailed instruction how to create Deriv API token and Applications
:::

### API Token
Expand Down Expand Up @@ -54,15 +55,13 @@ For more information on OAuth2, visit [this guide](https://aaronparecki.com/oau

Here is the visual representation of how the OAuth authorization connection works:

![OAuth flow](/img/how_oauth_works.png "OAuth flow")
![OAuth flow](/img/how_oauth_works.png 'OAuth flow')

## Authentication Process

In order to Authenticate your user, specify the URL that will be used as the OAuth Redirect URL on the [Dashboard](/dashboard) page, **Register application** tab in the **OAuth details** fields and then Add a login button on your website or app and direct users to **`https://oauth.binary.com/oauth2/authorize?app_id=your_app_id`** where your_app_id is the ID of your app.



![Deriv OAuth Login](/img/oauth_login.png "Deriv OAuth Login")
![Deriv OAuth Login](/img/oauth_login.png 'Deriv OAuth Login')

Once a user signs up / signs in, they will be redirected to the URL that you entered as the Redirect URL. This URL will have arguments added to it with the user's session tokens, and will look similar to this:

Expand All @@ -71,28 +70,32 @@ Once a user signs up / signs in, they will be redirected to the URL that you ent
## Authorization Process

The query params in the redirect URL are the user's accounts and their related session tokens. you can map the query params to an array like so:

```js
const user_accounts = [
{
account: "cr799393",
token: "a1-f7pnteezo4jzhpxclctizt27hyeot",
currency: "usd"
},
{
account: "vrtc1859315",
token: "a1clwe3vfuuus5kraceykdsoqm4snfq",
currency: "usd"
},
]
{
account: 'cr799393',
token: 'a1-f7pnteezo4jzhpxclctizt27hyeot',
currency: 'usd',
},
{
account: 'vrtc1859315',
token: 'a1clwe3vfuuus5kraceykdsoqm4snfq',
currency: 'usd',
},
];
```
To authorize the user, based on the user's **Selected** account, call the [authorize](https://api.deriv.com/api-explorer#authorize) API call with the user's **Selected** account **Session Token**:

To authorize the user, based on the user's **Selected** account, call the [authorize](https://api.deriv.com/api-explorer#authorize) API call with the user's **Selected** account **Session Token**:

```js
{
"authorize": "a1-f7pnteezo4jzhpxclctizt27hyeot"
}
```

The response for the `authorize` call would be an object like so:

```js
{
"account_list": [
Expand Down Expand Up @@ -146,4 +149,5 @@ The response for the `authorize` call would be an object like so:
"user_id": 12345678
}
```
Now user is authorized and you use Deriv API calls on behalf of the account.

Now user is authorized and you use Deriv API calls on behalf of the account.