Authenticate
The Oracle Communications Session Border Controller (SBC) REST API only accepts requests over secure HTTPS connections. Unencrypted HTTP requests are rejected with a 426 Upgrade Required. To successfully authenticate to the SBC, send a POST request to the authentication endpoint using Basic Access Authentication.
Prerequisites
Prerequisite | More Information |
Enable HTTPS | Enable HTTPS |
The Authorization Header
The SBC uses Basic Authentication, so the client must send an Authorization
header that contains the literal string Basic
, a space, and the base64 encoding of the string admin:<password>
.
For example:
Authorization: Basic YWRtaW46Y29ycmVjdCBob3JzZSBiYXR0ZXJ5IHN0YXBsZQ==
The XML response contains an <accessToken>
element that contains the access token.
In subsequent calls, this access token must be passed in an Authentication
header that contains the literal string Bearer
, a space, and the access token.
For example:
Authorization: Bearer YWRtaW4sYWRtaW4sMjAxOC0wOC0wOSAxOToyNzowzVmM2FhNGMzZjMyZDlkNWJmYzg4O
Request an Access Token with cURL
- Send a POST request to the
/rest/{version}/auth/token
endpoint.Use the
--user
flag to automatically base64 encode a <username>:<password> string for Basic Authentication.curl -X POST \ --header "Accept: application/xml" \ --user admin:<password> \ 'https://10.0.0.2/rest/v1.1/auth/token'
- The response body includes an
<accessToken>
element that contains the access token.<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <response> <data> <accessToken>YWRtaW4sYWRtaW4sMjAxOC0wOC0wOSAxOToyNzowzVmM2FhNGMzZjMyZDlkNWJmYzg4O</accessToken> </data> <messages/> <links/> </response>
- Export the access token to a variable for convenient use in subsequent requests.
export TOKEN='YWRtaW4sYWRtaW4sMjAxOC0wOC0wOSAxOToyNzowzVmM2FhNGMzZjMyZDlkNWJmYzg4O'
- In subsequent requests, send the access token within the
Authentication
header, after the key wordBearer
.curl -X GET \ --header "Accept: application/xml" \ --header "Authorization: Bearer $TOKEN" \ 'https://10.0.0.2/rest/v1.1/configuration/elementTypes'
Request an Access Token with Python
The following example shows how to get and send an access token using Python 3.
import requests
import base64
from lxml import etree
# set the endpoint
auth_url = "https://10.0.0.2/rest/v1.1/auth/token"
# base64 encode "admin:<password>" for Basic Authentication
encoded_bytes = base64.encodestring(b"admin:<password>").strip()
encoded_str = encoded_bytes.decode('utf8')
# create the Authorization header with the base64-encoded credentials
auth_header = { "Authorization": "Basic " + encoded_str }
# send the POST request
resp = requests.post(auth_url, headers=auth_header)
# extract the token and create an Authorization header with the token
tree = etree.fromstring(bytes(resp.text, encoding='utf8'))
token = tree.xpath("//accessToken")[0].text
# include the token in all subsequent calls
token_header = { "Authorization": "Bearer " + token }