master17
master17

Reputation: 159

How to encode correctly for Sabre OAuth API?

Based on Sabre documentation i need to encode with Base64 the clientId:password. I did it and put it like per documentation:

Authorization: Basic valueBase64Encoded

But always gets an error

{"error":"invalid_client","error_description":"Credentials are missing or the syntax is not correct"}

I believe i put values correct in Base64 from my account in Sabre with seperate colon.

clientId:password

Also, three x-www-form-urlencoded values are attached to POST : grant_type, username, password

Where is my mistake? Or what should i do here? Thanks for a help

Upvotes: 1

Views: 166

Answers (3)

Dan Lagomarsino
Dan Lagomarsino

Reputation: 3

Here is the code for V2

import base64
import requests

#V2 encoding

EPR="XXXXXX"
PASSWORD="XXXXXXX"
PCC="XXXX"

USERID=f'V1:{EPR}:{PCC}:AA'

enc_UserID = base64.b64encode(USERID.encode()).decode()
print('client id: ' + enc_UserID)

enc_Pass =  base64.b64encode(PASSWORD.encode()).decode()
Token = f'{enc_UserID}:{enc_Pass}'

enc_token= base64.b64encode(Token.encode()).decode()

endpoint = "https://api.platform.sabre.com"
urlByService = "/v2/auth/token"
url = endpoint + urlByService

data = {'grant_type':'client_credentials'}
headers = {'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic ' + enc_token}

response = requests.post(url, headers=headers, data=data)

# Checking the response
if response.status_code == 200:
    print("Request was successful!")
    print("Response:", response.json())
else:
    print("Request failed with status code:", response.status_code)

print ("Post Request to: " + url)
print (f'data: {data}')
print (f'header: {headers}')
print (response)
print ("Response Message: " + response.text)

Upvotes: 0

Ben Bartels
Ben Bartels

Reputation: 1

It looks like you are referring to v3 of the API, and Coti is referring to v2 in her answer. I have not had success with v3 yet, but v2 is working for me.

Upvotes: 0

Coti Rassi
Coti Rassi

Reputation: 11

You have to encode your clientId and your password first. Follow this steps:

  1. Encode in Base64 this string V1:{yourUsername}:{yourPCC}:AA
  2. Encode in Base64 your password
  3. Encode in Base64 this {resultOfFirstStep}:{resultOfSecondStep}

The result of the third step should be your encode string

The body grant_type=client_credentials is correct

Upvotes: 1

Related Questions