Authenticate and refresh token quickstart

Authentication at api.video all begins with Bearer authentication. With Bearer authentication, you authenticate with your API key, then receive a JWT (JSON Web Token) access token and a JWT refresh token. The access token lasts for one hour and allows you to access all api.video services. When the token expires, you have two choices. You can use your API key again to get a new JWT access token and refresh token, or you can use the existing refresh token to retrieve a new token.

How you choose to implement authentication can vary when you handle it yourself, but api.video's clients make it easy by handling all of it for you.

Choose an api.video client

The clients offered by api.video include:

Installation

To install your selected client, do the following:

go get github.com/apivideo/api.video-go-client
composer require api-video/php-api-client
npm install @api.video/nodejs-client --save

...or with yarn: 
  
yarn add @api.video/nodejs-client
pip install api.video
Using Nuget
  
Install-Package ApiVideo

Authenticate

To authenticate, do the following:

  1. If you haven't, sign up for an api.video account.

  2. Go to your dashboard and retrieve your API key, you can use the Sandbox or the Production key.

  3. Now it's time to authenticate!

package main

import (
    "fmt"
    "os"
    apivideosdk "github.com/apivideo/api.video-go-client"
)

func main() {
    //Connect to production environment
    client := apivideosdk.ClientBuilder("YOUR_API_TOKEN").Build()
  
}
<?php
require __DIR__ . '/vendor/autoload.php';

$apiKey = 'your API key';
$apiVideoEndpoint = 'https://ws.api.video';

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new ApiVideo\Client\Client(
    $apiVideoEndpoint,
    $apiKey,
    $httpClient
);

?>
const ApiVideoClient = require('@api.video/nodejs-client');

(async () => {
    try {
        const client = new ApiVideoClient({ apiKey: "YOUR_API_TOKEN" });
        }
})();
# Use your api.video api key to retrieve an access token for use with the api.video
# API. Access tokens are good for one hour.

import apivideo

api_key = "your api key here"
client = apivideo.AuthenticatedApiClient(api_key)

# If you prefer to use the sandbox environment:
# client = apivideo.AuthenticatedApiClient(api_key, production=False)

client.connect()

# You can view the object like this. Use this for reference and testing only.

print(client.__dict__)
using System.Collections.Generic;
using System.Diagnostics;
using System;
using System.IO;
using ApiVideo.Api;
using ApiVideo.Client;
using ApiVideo.Model;

namespace Example
{
    public class Example
    {
        public static void Main()
        {
            var apiKey = "YOUR_API_KEY";

            var apiVideoClient = new ApiVideoClient(apiKey);
            // if you rather like to use the sandbox environment:
            // var apiVideoClient = new ApiVideoClient(apiKey, ApiVideo.Client.Environment.SANDBOX);
        }
    }
}

Conclusion

After you've set up your client, you can now connect to any api.video endpoint and refreshing your token is handled for you by each client.


Did this page help you?