@@ -24,7 +24,7 @@ def authenticate_rdp(machine_id, password, app_key, url) -> dict:
2424 response .raise_for_status () # Raise an exception for 4xx/5xx HTTP errors
2525 return response .json ()
2626
27- def get_chain (ric , token , url ):
27+ def get_chain (ric , token , url ) -> dict :
2828 """Fetch chain data for a single RIC symbol using an access token."""
2929 # Bearer token is required for authorized API requests.
3030 headers = {
@@ -40,7 +40,7 @@ def get_chain(ric, token, url):
4040 response .raise_for_status ()
4141 return response .json ()
4242
43- def post_historical_event (rics , token , url ):
43+ def post_historical_event (rics , token , url ) -> dict :
4444 """Request historical event data for multiple RICs."""
4545 # Send the token in Authorization header for API access.
4646 headers = {
@@ -58,6 +58,18 @@ def post_historical_event(rics, token, url):
5858 response .raise_for_status ()
5959 return response .json ()
6060
61+ def post_authen_revoke (token , appkey , url ) -> None :
62+ """Revoke the access token to end the session."""
63+ headers = {
64+ "Content-Type" : "application/x-www-form-urlencoded"
65+ }
66+
67+ payload = f"token={ token } "
68+ auth = httpx .BasicAuth (username = appkey , password = "" )
69+
70+ response = httpx .post (url , data = payload , headers = headers , auth = auth , verify = False )
71+ response .raise_for_status ()
72+
6173def main () -> None :
6274 """Run the end-to-end demo: auth, chain data, and historical events."""
6375 # Load key/value pairs from src/.env into process environment.
@@ -67,7 +79,7 @@ def main() -> None:
6779 machine_id = os .getenv ("MACHINEID_RDP" )
6880 password = os .getenv ("PASSWORD_RDP" )
6981 app_key = os .getenv ("APPKEY_RDP" )
70- base_url = os .getenv ("BASE_URL_RDP " ) # Default to Refinitiv API base URL if not set
82+ base_url = os .getenv ("RDP_BASE_URL " ) # Default to Refinitiv API base URL if not set
7183
7284 # OAuth token endpoint used to obtain access token.
7385 url = f"{ base_url } /auth/oauth2/v1/token"
@@ -113,6 +125,16 @@ def main() -> None:
113125 print (f"HTTP error while posting historical event data: { e .response .status_code } - { e .response .text } " )
114126 except httpx .RequestError as e :
115127 print (f"Request error while posting historical event data: { e } " )
128+
129+ revoke_url = f"{ base_url } /auth/oauth2/v1/revoke"
130+ try :
131+ print ("Revoking access token..." )
132+ post_authen_revoke (token_data ["access_token" ], app_key , revoke_url )
133+ print ("Access token revoked successfully." )
134+ except httpx .HTTPStatusError as e_revoke :
135+ print (f"HTTP error while revoking token: { e_revoke .response .status_code } - { e_revoke .response .text } " )
136+ except httpx .RequestError as e_revoke :
137+ print (f"Request error while revoking token: { e_revoke } " )
116138 else :
117139 print ("Failed to receive access token. Exiting..." )
118140 sys .exit (1 )
0 commit comments