Skip to main contentIBM Video Streaming Developers

Authentication

Authorization flows

The OAuth 2.0 protocol provides several workflows for authorizing a user and obtaining an access token. It depends on the type and architecture of the client which flow is the most suitable. The following workflows are supported:

  • Authorization Code: Suitable for third-party websites which contain a client and a server component.
  • Client Credentials: Best choice for users developing server-side applications to manage their content or settings.

Authorization Code flow

  1. The user enters credentials to a secure login webpage.
  2. After logging in, the browser is redirected to a special URL (defined by the client), passing an authorization code in the URL.
  3. The third-party server obtains the access token with another HTTP request in the background, using the authorization code.

See the OAuth 2.0 Authorization Framework (https://tools.ietf.org/html/rfc6749) for details.

Client Credentials flow

Client credentials can be generated on the Video Streaming dashboard. The client obtains an access token using the client_id and client_secret. With this token the user’s server-side application can access the resources of the account which is identified by this client_id/client_secret pair.

Authorizing the user

Authorization endpoint
Locationhttps://authentication.video.ibm.com/authorize
Supported HTTP methodsGET, POST
Supported flowsAuthorization Code

The authorization endpoint is a secure web page that authenticates the user. The client should show this page to the user in an embedded browser. When the user completes the login process the browser is redirected to a special URL. The client can capture this redirect call and obtain an authorization code.

Parameters

The parameters below specify the behavior of the authorization endpoint. These have to be set in GET or POST HTTP parameters.

Supported OAuth 2.0 standard parameters
PARAMETERTYPEIMPORTANCEDESCRIPTION
response_typestringREQUIREDcode for Authorization Code flow
client_idstringREQUIRED40-character long string that identifies the client. Provided by IBM Video Streaming.
redirect_uristringREQUIREDThe URI where the browser will redirect after the authentication process. This URI must be registered at IBM Video Streaming.
statestringOPTIONALThis value is sent as a GET parameter to the redirect_uri to maintain state between the request and callback. See the OAuth 2.0 Authorization Framework (https://tools.ietf.org/html/rfc6749) for details.
scopestringOPTIONALWhitelist-separated list of the requested scopes.
IBM Video Streaming specific extra parameters
PARAMETERTYPEIMPORTANCEDESCRIPTION
device_namestringOPTIONALFull product name of the client device or application. It is used for easy identification of the OAuth 2.0 token. The user will be able to review which clients are connected to his/her account, and revoke this access on the IBM Video Streaming website.
langstringOPTIONALShow the authorization page in this locale (e.g. en_US); This parameter will also set the language of the newly registered users.

Response values

The response values below are appended to the redirect_uri as HTTP GET parameters.

Authorization Code flow

If the response_type parameter is code, the following properties are returned:

PROPERTYDESCRIPTION
codeAn authorization code (40-character long string)
stateIf state was sent to the endpoint, this information is

Error handling

If the authentication was not successful, there is no HTTP redirection: the user can stay on the Authorization Endpoint page until the correct credentials are entered. It is also possible to request a password reset if the password is forgotten.

If the user authenticates correctly, but interrupts the authorization flow, e.g. by pressing a Deny button on the authorization page, the browser is redirected to the redirect_uri with the following parameters:

NAMEDESCRIPTION
erroraccess_denied
stateIf state was sent to the endpoint, this information is sent back

Obtain an access token

Token Endpoint
Locationhttps://video.ibm.com/oauth2/token
Supported HTTP methodsPOST

Authorization Code flow

When the client receives the authorization code the server-side component of the client calls the token endpoint to return the access token.

Parameters

The following parameters must be set as HTTP POST parameters:

PARAMETERTYPEIMPORTANCEDESCRIPTION
grant_typestringREQUIREDMUST be authorization_code in this case.
client_idstringREQUIRED40-character long string, provided by IBM Video Streaming
codestringREQUIREDThe authorization code received from the authorization endpoint
redirect_uristringREQUIREDThe redirection URI used by the authorization server to return the authorization response in the previous step

In addition to the parameters above, the client must provide its client secret (provided along with the client key) to authenticate itself. The authentication is done with HTTP Basic authorization method.

Example HTTP header:

Authorization: Basic bc345abc45d6789abcdef0123aef0126789def01

Success response

The response of the Token Endpoint is a JSON object.

JSON response upon success:

NAMEDESCRIPTION
id_tokenThis property is only returned if your request included an openid scope. The value is a JSON Web Token (JWT) that contains digitally signed identity information about the user.
access_tokenAccess token (40-character long string)
refresh_tokenA token that you can use to obtain a new access token
token_typeWill be Bearer Token
expires_inToken’s current lifetime, in seconds.

Example

The following is an example of the authorization code flow.

1 - The client opens a browser with the authorization endpoint:

https://authentication.video.ibm.com/authorize
?response_type=code
&client_id=AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD
&redirect_uri=http://example.com/get_access_token
&device_name=My%20Device
&scope=broadcaster
&state=XYZ

2 - The user enters his/her credentials and presses the Allow button. The browser is redirected to the following URL:

http://example.com/get_access_token?code=19d8dbb3ebac55f110c3b526e38bcfdfbf46d659&state=XYZ

3 - The page handler at http://example.com/get_access_token retrieves the Access Token using the Token Endpoint:

POST /oauth2/token HTTP/1.1
Host: video.ibm.com
Authorization: Basic xxxxxxxxxxyyyyyyyyyywwwwwwwwwwzzzzzzzzzz
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&client_id=AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD
&code=19d8dbb3ebac55f110c3b526e38bcfdfbf46d659&redirect_uri=http://example.com/get_access_token

4 - The response of token endpoint contains the access token:

HTTP/1.1 200 OK
Cache-Control: no-store
Content-Type:application/json; charset=UTF-8
{"access_token":"ab345cdef123ef1267890abcdef04567890abcd1", "refresh_token":"cb12cdef123ef1267890abcdef04567890abcd1","token_type":"bearer", "expires_in":86400}

Client Credentials flow

Parameters

The following parameters must be set as HTTP POST parameters:

PARAMETERTYPEIMPORTANCEDESCRIPTION
grant_typestringREQUIREDMUST be client_credentials in this case.
client_idstringREQUIRED40-character long string, provided by IBM Video Streaming.
device_namestringOPTIONALdevice name
scopestringOPTIONALbroadcaster for broadcaster scope, or space separated URL encoded list of these strings

In addition to the parameters above, the client must provide its client secret (provided along with the client key) to authenticate itself. The authentication is done with HTTP Basic authorization method.

Example HTTP header:

Authorization: Basic bc345abc45d6789abcdef0123aef0126789def01
Success response
NAMEDESCRIPTION
id_tokenThis property is only returned if your request included an openid scope. The value is a JSON Web Token (JWT) that contains digitally signed identity information about the user.
access_tokenAccess token (40-character long string)
refresh_tokenA token that you can use to obtain a new access token
token_typeWill be bearer
expires_inToken’s current lifetime, in seconds.
Possible error responses
HTTP RESPONSE CODEERROR VALUEERROR CONDITIONS
400 Bad Requestinvalid_clientThe referred client is missing, the secret is wrong or the authorization requester client and token requester client does not match.
400 Bad Requestinvalid_grantThe supplied authorization_code does not exist or expired
400 Bad Requestinvalid_requestOne or more required parameters are missing
501 Not Implementedunsupported_grant_typeThe client asks for an unsupported grant type, currently only authorization_code, client_credentials and refresh_token are supported.
503 Server Errorserver_errorThe server cannot handle the request at this moment for some reason. Try again later.

Refreshing access tokens

When access tokens expire or become invalid, applications can obtain a new access token using a refresh token without prompting users to enter their login credentials again. The refresh token is returned as a response of one of the previous token requests. Because refresh tokens are last for 30 days, developers should ensure that strict storage requirements are in place to keep them from being leaked.

Parameters

The following parameters must be set as HTTP POST parameters:

PARAMETERTYPEIMPORTANCEDESCRIPTION
grant_typestringREQUIREDMUST be refresh_token.
refresh_tokenstringREQUIREDA token that you can use to obtain a new access token. Refresh tokens are valid for 30 days or until the user revokes access.
client_idstringREQUIREDClient id provided by IBM Video Streaming.

In addition to the parameters above, the client must provide its client secret (provided along with the client key) to authenticate if the client acts as a “web application”. Sending client secret can be omitted in case of “native application”. The authentication is done with HTTP Basic authorization method.

Example HTTP header:

Authorization: Basic bc345abc45d6789abcdef0123aef0126789def01

Success response

The response of the Token Endpoint is a JSON object.

JSON response upon success are:

NAMEDESCRIPTION
id_tokenThis property is only returned if your request included an openid scope. The value is a JSON Web Token (JWT) that contains digitally signed identity information about the user.
access_tokenAccess token (40-character long string)
refresh_tokenA token that you can use to obtain a new access token
token_typeWill be Bearer Token
expires_inToken’s current lifetime, in seconds.

Example

Previous token endpoint response:

{
"access_token": "ab345cdef123ef1267890abcdef04567890abcd1",
"refresh_token": "cb345cdef123ef1267890abcdef04567890abcd1",
"token_type": "bearer",
"expires_in": 86400
}

Refresh token request:

POST /oauth2/token HTTP/1.1
Host: video.ibm.com
Authorization: Basic xxxxxxxxxxyyyyyyyyyywwwwwwwwwwzzzzzzzzzz
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&client_id=AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD&refresh_token=cb345cdef123ef1267890abcdef04567890abcd1

Refresh token response:

{
"access_token": "db345cdef123ef1267890abcdef04567890abcd1",
"refresh_token": "eb345cdef123ef1267890abcdef04567890abcd1",
"token_type": "bearer",
"expires_in": 86400
}