1010from jwt import JWT
1111import httpx
1212import websockets .client
13+ from authlib .integrations .httpx_client import AsyncOAuth2Client
14+
1315
1416URL = "wss://gateway-vaas.gdatasecurity.de"
1517
18+
1619class VaasTracing :
1720 """Tracing interface for Vaas"""
1821
@@ -37,7 +40,7 @@ def __init__(self, tracing=VaasTracing()):
3740 async def connect (self , token , url = URL ):
3841 """Connect to VaaS
3942
40- token -- a OpenID Connect token signed by a trusted identity provider
43+ token -- OpenID Connect token signed by a trusted identity provider
4144 """
4245 self .websocket = await websockets .client .connect (url )
4346 authenticate_request = {"kind" : "AuthRequest" , "token" : token }
@@ -53,6 +56,22 @@ async def connect(self, token, url=URL):
5356 self .__receive_loop ()
5457 ) # fire and forget async_foo()
5558
59+ async def connect_with_client_credentials (
60+ self , client_id , client_secret , token_endpoint , url = URL , verify = True
61+ ):
62+ """Connect to VaaS with client credentials grant
63+
64+ :param str client_id: Client ID provided by G DATA
65+ :param str client_secret: Client secret provided by G DATA
66+ :param str token_endpoint: Token endpoint of identity provider
67+ :param str url: Websocket endpoint for verdict requests
68+ :param bool verify: This switch turns off SSL validation when set to False; default: True
69+
70+ """
71+ async with AsyncOAuth2Client (client_id , client_secret , verify = verify ) as client :
72+ token = (await client .fetch_token (token_endpoint ))["access_token" ]
73+ await self .connect (token , url )
74+
5675 async def close (self ):
5776 """Close the connection"""
5877 if self .websocket is not None :
0 commit comments