Python API - 401 - 'Auth scheme not supported - AnaplanCertificate'
Hi all,
I tried to use the certificate authentication method with the Python API. I used one of the many Python scripts provided but I get a 401 Response : 'Auth scheme not supported - AnaplanCertificate'.
Do you know if it is required to enable the Anaplan certificate authentication method somewhere in order to use it ?
Thank you very much for your help,
Joël
# This script returns the metadata for each chunk in a file to a json array # saved in file 'chunkData.json'. # This script assumes you know the workspaceGuid, modelGuid, and fileID for the # file you want to check. If you do not know this information, please run # 'getWorkspaces.py', 'getModels.py', and 'getFiles.py' respectively. # If you are using certificate authentication, this script assumes you have # converted your Anaplan certificate to PEM format, and that you know the # Anaplan account email associated with that certificate. # This script uses Python 3 and assumes that you have the following modules # installed: requests, base64 import requests import base64 # Insert your workspace Guid wGuid = '' # Insert your model Guid mGuid = '' # Insert your file ID fileID = '' # Insert the Anaplan account email being used username = '' # If using cert auth, replace cert.pem with your pem converted certificate # filename. Otherwise, remove this line. cert = open('cert.pem').read() # If using basic auth, insert your password. Otherwise, remove this line. password = '' # Uncomment your authentication method (cert or basic). Remove the other. user = 'AnaplanCertificate ' + str(base64.b64encode(( f'{username}:{cert}').encode('utf-8')).decode('utf-8')) # user = 'Basic ' + str(base64.b64encode((f'{username}:{password}' # ).encode('utf-8')).decode('utf-8')) getHeaders = { 'Authorization': user } getChunkData = requests.get('https://api.anaplan.com/1/3/workspaces/' + f'{wGuid}/models/{mGuid}/files/{fileID}' + '/chunks', headers=getHeaders) with open('chunkData.json', 'wb') as f: f.write(getChunkData.text.encode('utf-8'))
Answers
-
Hi,
The part of this script responsible for Cert based authentication doesn't look correct at all. It incorrectly assumes that cert is something like a password - which is not true. In reality, what need to happen, is that you script needs to generate random string, then sign it using private key from cert, and send both to server in headers field, like: {
"encodedData": "{encoded_string}",
"encodedSignedData" : {encoded_signed_string}
}
More info: https://anaplanauthentication.docs.apiary.io/#0 -
This code us calling the API v1.3 code. Certificates of any type are not supported on that version. To use CA certificates you need to use API v2.0
It uses a Authentication API: https://anaplanauthentication.docs.apiary.io/#
And the integration API: https://anaplanbulkapi20.docs.apiary.io/#
Scott
0 -
Hi Joel,
were you able to get the python script updated? I'm running into the same problem right now.
0