Re: Token Validation Error VTS

Solved! Go to solution
mooaz624
Regular Visitor

Token Validation Error VTS

I'm trying to make an API call to COF data inquiry, but I'm getting the following error: {'responseStatus': {'status': 401, 'code': '9210', 'severity': 'ERROR', 'message': 'Token validation failed', 'info': ''}}
This is the code
 
import datetime
from distutils import debug
import time
import json
import ast
import logging
import requests
from jwcrypto import jwk, jwe





myKey_ID  = 'bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a'
server_cert = 'server_cert_bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a.pem'
private_key = 'key_bf4e64ce-0e41-4a73-9a3d-f8ed8d25133a.pem'






def encrypt(payload, server_cert, myKey_ID😞
    payload = json.dumps(payload)
    protected_header = {
            "alg": "RSA-OAEP-256",
            "typ":"JOSE",
            "enc": "A128GCM",
            "kid": myKey_ID,
            "channelSecurityContext":"RSA_PKI",
            "iat": int(round(time.time() * 1000))
        }
    jwetoken = jwe.JWE(payload.encode('utf-8'),
                            recipient=loadPem(server_cert),
                            protected=protected_header)
    encryptedPayload = jwetoken.serialize(compact=True)
    return {"encData": encryptedPayload}  




def decrypt(encPayload, private_key😞
    print(encPayload);
    if type(encPayload) is str:
        payload = json.loads(encPayload)
    if encPayload.get('encData', True😞
        jwetoken = jwe.JWE()
        jwetoken.deserialize(encPayload["encData"], key=loadPem(private_key))
        return jwetoken.payload
    return encPayload

 

def loadPem(filePath😞
    with open(filePath, "rb") as pemfile:
        return jwk.JWK.from_pem(pemfile.read())






print("START Sample Code for Two-Way (Mutual) SSL")

 

print(datetime.datetime.now())
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")

 

 

headers = { "content-type": "application/json",
            'accept': 'application/json',
            'keyId': myKey_ID
            }

 

body = {}

 

payload = json.loads('''{ "requestHeader":{
      "requestMessageId":"6da6b8b024532a2e0eacb1af58581",
      "messageDateTime":"'''+ date +'''"
   },
   "requestData":{
      "pANs":[
         4072208010000000
      ],
      "group":"STANDARD"
   }
   
   }''')



user_id = 'RPNXAMSRCKPXKLZ1C42F21JX4aWTmPRVJT7l5RSJh9ts6r-6c'
password = 'r2AOqpk7nf0yZ6hKF3oYIIn7Vq'



cert = 'cert.pem'
key = 'key_974255ae-5455-486e-ac2c-a13630debe20.pem'

 

timeout = 10

 

encryptedPayload = encrypt(payload, server_cert, myKey_ID)



try:
    response = requests.post(url,
                            cert=(cert, key),
                            headers = headers,
                            auth=(user_id, password),
                            json = encryptedPayload,
                            timeout=timeout
                            )
except Exception as e:
    print(e)



decryptedPayload = decrypt(response.json(), private_key)



data = ast.literal_eval(decryptedPayload.decode('utf8'))

 

print("Decrypted payload",data)



var1 = str(response.status_code)
var2 = '200'
msg = " Two-Way (Mutual) SSL test failed"
assert var1 == var2, msg
print("END Sample Code for Two-Way (Mutual) SSL\n\n")


When I debug I get this

visa_issue.PNG

Sorry for the bad english and I would appreciate any type of help.I'm doing this for the visa virtual internship program and trying to learn as much as I can.

6 REPLIES 6
cathy2981
Community Moderator

Re: Token Validation Error VTS

We appreciate you bringing this to our attention, @mooaz624 . We have let our team know and an agent will follow up with any information. - Cathy

mooaz624
Regular Visitor

Re: Token Validation Error VTS

Ok thanks 🙏
I_Doroteo3
Visa Developer Support Specialist

Re: Token Validation Error VTS

Hi @mooaz624

 

Because Visa Token Services is a restricted product, please reach out to your Visa Account Executive, Gateway or Acquiring partner, and/or visit our detailed Product page at Visa Ready.

 

You also can submit specific queries about the product through Visa Ready using the “Contact Us” link.

 

Thanks, 

Illana

mooaz624
Regular Visitor

Re: Token Validation Error VTS

I'm sorry I probably didn't explain my problem well, but I'm trying to use the Card On File Data API because this is the task given to me in the visa virtual internship program. So just to make sure I understood correctly this is restricted? Because there was nothing said about it being restricted in the explanation of the task.
mooaz624
Regular Visitor

Re: Token Validation Error VTS

I figured out how to solve my problem it was my date and time settings. Thank you @I_Doroteo3 for the response and sorry for taking your time.
jonesscruzz
Dabbler

Re: Token Validation Error VTS

Ok thanks :folded_hands: