|
|
|
@ -18,26 +18,29 @@ class OAuthHandler(BasePluginClient):
|
|
|
|
redirect_uri: str,
|
|
|
|
redirect_uri: str,
|
|
|
|
system_credentials: Mapping[str, Any],
|
|
|
|
system_credentials: Mapping[str, Any],
|
|
|
|
) -> PluginOAuthAuthorizationUrlResponse:
|
|
|
|
) -> PluginOAuthAuthorizationUrlResponse:
|
|
|
|
response = self._request_with_plugin_daemon_response_stream(
|
|
|
|
try:
|
|
|
|
"POST",
|
|
|
|
response = self._request_with_plugin_daemon_response_stream(
|
|
|
|
f"plugin/{tenant_id}/dispatch/oauth/get_authorization_url",
|
|
|
|
"POST",
|
|
|
|
PluginOAuthAuthorizationUrlResponse,
|
|
|
|
f"plugin/{tenant_id}/dispatch/oauth/get_authorization_url",
|
|
|
|
data={
|
|
|
|
PluginOAuthAuthorizationUrlResponse,
|
|
|
|
"user_id": user_id,
|
|
|
|
data={
|
|
|
|
"data": {
|
|
|
|
"user_id": user_id,
|
|
|
|
"provider": provider,
|
|
|
|
"data": {
|
|
|
|
"redirect_uri": redirect_uri,
|
|
|
|
"provider": provider,
|
|
|
|
"system_credentials": system_credentials,
|
|
|
|
"redirect_uri": redirect_uri,
|
|
|
|
|
|
|
|
"system_credentials": system_credentials,
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
headers={
|
|
|
|
headers={
|
|
|
|
"X-Plugin-ID": plugin_id,
|
|
|
|
"X-Plugin-ID": plugin_id,
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for resp in response:
|
|
|
|
for resp in response:
|
|
|
|
return resp
|
|
|
|
return resp
|
|
|
|
raise ValueError("No response received from plugin daemon for authorization URL request.")
|
|
|
|
raise ValueError("No response received from plugin daemon for authorization URL request.")
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
raise ValueError(f"Error getting authorization URL: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
def get_credentials(
|
|
|
|
def get_credentials(
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|
@ -53,31 +56,34 @@ class OAuthHandler(BasePluginClient):
|
|
|
|
Get credentials from the given request.
|
|
|
|
Get credentials from the given request.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# encode request to raw http request
|
|
|
|
|
|
|
|
raw_request_bytes = self._convert_request_to_raw_data(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response = self._request_with_plugin_daemon_response_stream(
|
|
|
|
try:
|
|
|
|
"POST",
|
|
|
|
# encode request to raw http request
|
|
|
|
f"plugin/{tenant_id}/dispatch/oauth/get_credentials",
|
|
|
|
raw_request_bytes = self._convert_request_to_raw_data(request)
|
|
|
|
PluginOAuthCredentialsResponse,
|
|
|
|
response = self._request_with_plugin_daemon_response_stream(
|
|
|
|
data={
|
|
|
|
"POST",
|
|
|
|
"user_id": user_id,
|
|
|
|
f"plugin/{tenant_id}/dispatch/oauth/get_credentials",
|
|
|
|
"data": {
|
|
|
|
PluginOAuthCredentialsResponse,
|
|
|
|
"provider": provider,
|
|
|
|
data={
|
|
|
|
"redirect_uri": redirect_uri,
|
|
|
|
"user_id": user_id,
|
|
|
|
"system_credentials": system_credentials,
|
|
|
|
"data": {
|
|
|
|
# for json serialization
|
|
|
|
"provider": provider,
|
|
|
|
"raw_http_request": binascii.hexlify(raw_request_bytes).decode(),
|
|
|
|
"redirect_uri": redirect_uri,
|
|
|
|
|
|
|
|
"system_credentials": system_credentials,
|
|
|
|
|
|
|
|
# for json serialization
|
|
|
|
|
|
|
|
"raw_http_request": binascii.hexlify(raw_request_bytes).decode(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
headers={
|
|
|
|
|
|
|
|
"X-Plugin-ID": plugin_id,
|
|
|
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
headers={
|
|
|
|
for resp in response:
|
|
|
|
"X-Plugin-ID": plugin_id,
|
|
|
|
return resp
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
raise ValueError("No response received from plugin daemon for authorization URL request.")
|
|
|
|
},
|
|
|
|
except Exception as e:
|
|
|
|
)
|
|
|
|
raise ValueError(f"Error getting credentials: {e}")
|
|
|
|
for resp in response:
|
|
|
|
|
|
|
|
return resp
|
|
|
|
|
|
|
|
raise ValueError("No response received from plugin daemon for authorization URL request.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _convert_request_to_raw_data(self, request: Request) -> bytes:
|
|
|
|
def _convert_request_to_raw_data(self, request: Request) -> bytes:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|