Code Exchange

Parameters
grant_type:For a code exchange, this value should be set to authorization_code
redirect_uri:Redirect URI of your Restream API application
code:Code, received from the previous method: Capture the code
client_id:Client id of your Restream API application
client_secret:Client secret of your Restream API application

There are two ways to exchange a code for an access / refresh token pair:

  1. Using a Basic Auth header to send the client_id and client_secret
  2. Use the client_id and client_secret as part of the x-www-form-urlencoded body
Tip

Use the Basic Auth header to prevent passing confidential information as part of a query string that could be logged. For example a web server hosting an Nginx load balancer could log the request with the full query string.

You can exchange the received code for token by sending a POST request to the following URL:

curl -X POST \
     -H "Content-Type: application/x-www-form-urlencoded" \
     --user [your client id]:[your client secret] \
     --data "grant_type=authorization_code&redirect_uri=[your redirect URI]&code=[code]" \
     https://api.restream.io/oauth/token

Upon a successful exchange, you will receive a pair of tokens with their expiration times. The expiration time for access tokens is 1 hour and 1 year for refresh tokens from the time of grant.

Response

Success
Error
{
  "access_token": "2a407cfcfdf8920242fd6dc7e5f83c86374ef925",
  "expires": 1520280067,
  "expires_in": 3600,
  "refresh_token": "9ca0e1e99ae3eae136a2bd98fc9c1534ea928ed3",
  "scope": "profile.read channels.read chat.read stream.read",
  "token_type": "Bearer",
  "accessToken": "2a407cfcfdf8920242fd6dc7e5f83c86374ef925",
  "accessTokenExpiresIn": 3600,
  "accessTokenExpiresAt": "2018-03-05T20:01:07.215Z",
  "accessTokenExpiresEpoch": 1520280067,
  "refreshToken": "9ca0e1e99ae3eae136a2bd98fc9c1534ea928ed3",
  "refreshTokenExpiresIn": 31536000,
  "refreshTokenExpiresAt": "2019-03-05T19:01:07.215Z",
  "refreshTokenExpiresEpoch": 1551812467,
  "scopeJson": [
    "profile.read",
    "channels.read",
    "chat.read",
    "stream.read"
  ],
  "tokenType": "Bearer"
}