Skip to content

Commit

Permalink
use the supplied auth token
Browse files Browse the repository at this point in the history
explicit authentication will soon become mandatory
  • Loading branch information
pschichtel committed Dec 18, 2024
1 parent 9209fe6 commit 323a4b3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions rasa_vier_cvg/cvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RESELLER_TOKEN_FIELD = "resellerToken"
PROJECT_TOKEN_FIELD = "projectToken"
CALLBACK_FIELD = "callback"
AUTH_TOKEN_FIELD = "authToken"

T = TypeVar('T')

Expand Down Expand Up @@ -66,16 +67,20 @@ class CVGOutput(OutputChannel):

on_message: Callable[[UserMessage], Awaitable[Any]]
base_url: str
headers: Dict[str, str]
proxy: Optional[str]

@classmethod
def name(cls) -> Text:
return CHANNEL_NAME

def __init__(self, callback_base_url: Text, on_message: Callable[[UserMessage], Awaitable[Any]], proxy: Optional[str], task_container: TaskContainer, blocking_output: bool) -> None:
def __init__(self, callback_base_url: Text, auth_token: Text, on_message: Callable[[UserMessage], Awaitable[Any]], proxy: Optional[str], task_container: TaskContainer, blocking_output: bool) -> None:
self.on_message = on_message

self.base_url = callback_base_url.rstrip('/')
self.headers = {
"Authorization": f"Bearer {auth_token}",
}
self.proxy = proxy
self.task_container = task_container
self.blocking_output = blocking_output
Expand All @@ -95,7 +100,7 @@ async def _perform_request_sync(self, path: str, method: str, data: Optional[any
status = -1
body = None
try:
async with aiohttp.request(method, url, json=data, proxy=self.proxy) as res:
async with aiohttp.request(method, url, json=data, proxy=self.proxy, headers=self.headers) as res:
status = res.status
if status == 204:
return status, {}
Expand Down Expand Up @@ -316,9 +321,17 @@ async def _process_message(self, request: Request, on_new_message: Callable[[Use
text = text[:-1]

metadata = make_metadata(request.json)
cvg_output = CVGOutput(
request.json[CALLBACK_FIELD],
request.json[AUTH_TOKEN_FIELD],
on_new_message,
self.proxy,
self.task_container,
self.blocking_output
)
user_msg = UserMessage(
text=text,
output_channel=CVGOutput(request.json[CALLBACK_FIELD], on_new_message, self.proxy, self.task_container, self.blocking_output),
output_channel=cvg_output,
sender_id=sender_id,
input_channel=CHANNEL_NAME,
metadata=metadata,
Expand Down

0 comments on commit 323a4b3

Please sign in to comment.