kiota: Error accessing authenticated endpoint with plain HTTP endpoint [HTTPError: Only https is supported]
What are you generating using Kiota, clients or plugins?
API Client/SDK
In what context or format are you using Kiota?
Windows executable
Client library/SDK language
Python
Describe the bug
I am trying to access an authenticated HTTP endpoint - not HTTPS. However it appears that authentication must take place over HTTPS.
Expected behavior
Both the authentication call and the final api call should succeed
How to reproduce
The following code using only httpx works fine when the baseUri is “http://mySvc”. Note this is an authenticated service-to-service call within a single Azure Container vnet - only an HTTP endpoint is exposed, not HTTPS.
def get_my_foo(baseUri, id):
scope = "api://xxxxx/.default"
credential = ChainedTokenCredential(ManagedIdentityCredential(), DefaultAzureCredential())
token = credential.get_token(scope).token
with httpx.Client() as client:
headers = { "Authorization": f"Bearer {token}" }
response = client.get(f"{baseUri}/foos/{id}", headers=headers)
response.raise_for_status() # This will raise an exception for 4xx/5xx errors
return response.json()
However, using this kiota generated client:
credential = ChainedTokenCredential(ManagedIdentityCredential(), DefaultAzureCredential() )
# Note that no combination of these params makes any difference here
http_client = httpx.AsyncClient(verify = False, follow_redirects = True)
auth_provider = AzureIdentityAuthenticationProvider(credential, scopes=adt_api_scope)
request_adapter = HttpxRequestAdapter(
http_client = http_client,
authentication_provider = auth_provider,
base_url = self.base_url)
client = MyClientKiota(request_adapter)
Does not work when calling client.foos.by_id(id). The error I get is:
File "/usr/local/lib/python3.12/site-packages/kiota_authentication_azure/azure_identity_access_token_provider.py", line 78, in get_authorization_token
raise exc
kiota_authentication_azure._exceptions.HTTPError: Only https is supported
This appears to be because that while my actual internal service call needs to be plain HTTP, then auth call needs to be HTTPS. How do I get the kiota client to behave like the httx code, (apparently) still using HTTPS to get the token, but using HTTP to access my endpoint?
Open API description file
No response
Kiota Version
1.17.0+1eb16cd65853c17179e2dde3ae6098135deacf55
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
No response
Configuration
No response
Debug output
Click to expand log
``` <log output here></details>
### Other information
_No response_
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (8 by maintainers)
It’s unfortunate that additional hoop jumping is added by a check that cannot be turned off. I understand that insecure apps are a pain but it’s not Microsoft/Kiotas job to police these kinds of things. This should be toggleable via a switch, and if an original design decision is found to be flawed (as this comment trail indicates) then really, it should be revisited and patched out.
EDIT: In my case this actually introduces a security problem. I have a console app that submits things to localhost on the server. The server is exposed to the internet via Caddy (which is like nginx). The console app could actually submit things over the unsecured localhost API just fine, because that would never be exposed to the internet. But instead, now I have to expose that bit of my app that should be internal only so it can be behind a secured SSL endpoint so the API can work correctly on localhost.
When it comes to design decisions like these, you can’t be sure you won’t introduce unintended negative consequences. And essentially that’s what has happened here. If the opinion has changed then this should be patched out by the core team, not really relying on third-party contributors to right an incorrect design decision.
Thank you for the additional information.
An alternative (and arguably better) design here would be to make the localhost_strings configurable with a better name like “HostsToAllowHttp” or something like that. It could reuse the entirety of the ValidHosts infrastructure, leading to minimal duplication in the implementation.
But again, I’ll like a sign off from @darrelmiller before we proceed here.