Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetToken and asyncify: Algorithm not supported #498

Closed
5 tasks done
basilfx opened this issue Jun 12, 2023 · 2 comments · Fixed by #499
Closed
5 tasks done

GetToken and asyncify: Algorithm not supported #498

basilfx opened this issue Jun 12, 2023 · 2 comments · Fixed by #499
Labels
bug This points to a verified bug in the code

Comments

@basilfx
Copy link

basilfx commented Jun 12, 2023

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

When wrapping GetToken with asyncify, it passes the wrong arguments via the wrapper, and it fails with an exception 'Algorithm not supported'.

I believe the error resides here. When I debug this piece of code, I see that it initializes the AuthenticationBase with client_assertion_signing_alg = "https". That makes me believe that the order of the arguments passed onto asyncify(GetToken) -> GetToken ->AuthenticationBase is incorrect when using asyncify.

Reproduction

This is what I basically do (I'm migrating from 3.x to 4.x):

AsyncGetToken = asyncify(GetToken)

get_token = AsyncGetToken(domain, client_id)

# This fails with 'Algorithm not supported'.
response = await self.get_token.login_async(
    username=username,
    password=password,
    realm="Username-Password-Authentication",
    scope="openid profile email",
)

Additional context

Stack trace:

Traceback (most recent call last):
  File "lib/python3.10/site-packages/jwt/api_jws.py", line 95, in get_algorithm_by_name
    return self._algorithms[alg_name]
KeyError: 'https'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "cli.py", line 178, in run
    sys.exit(asyncio.run(main(sys.argv)))
  File "/usr/local/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python@3.10/3.10.12/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "cli.py", line 167, in main
    await command_devices(arguments)
  File "cli.py", line 55, in command_devices
    await account.update_devices()
  File "client.py", line 61, in update_devices
    device.id: device for device in await self.traccar_api.get_devices()
  File "api.py", line 49, in wrapper
    return await func(*args, **kwargs)
  File "api.py", line 217, in get_devices
    response = await self._get("devices")
  File "api.py", line 91, in wrapper
    return await func(*args, **kwargs)
  File "api.py", line 375, in _get
    await self.identity_api.login()
  File "api.py", line 154, in login
    response = await self.get_token.login_async(
  File "lib/python3.10/site-packages/auth0/asyncify.py", line 10, in closure
    return await m(*args, **kwargs)
  File "lib/python3.10/site-packages/auth0/authentication/get_token.py", line 156, in login
    return self.authenticated_post(
  File "lib/python3.10/site-packages/auth0/authentication/base.py", line 59, in authenticated_post
    url, data=self._add_client_authentication(data), headers=headers
  File "lib/python3.10/site-packages/auth0/authentication/base.py", line 45, in _add_client_authentication
    return add_client_authentication(
  File "lib/python3.10/site-packages/auth0/authentication/client_authentication.py", line 61, in add_client_authentication
    authenticated_payload["client_assertion"] = create_client_assertion_jwt(
  File "lib/python3.10/site-packages/auth0/authentication/client_authentication.py", line 23, in create_client_assertion_jwt
    return jwt.encode(
  File "lib/python3.10/site-packages/jwt/api_jwt.py", line 73, in encode
    return api_jws.encode(
  File "lib/python3.10/site-packages/jwt/api_jws.py", line 159, in encode
    alg_obj = self.get_algorithm_by_name(algorithm_)
  File "lib/python3.10/site-packages/jwt/api_jws.py", line 101, in get_algorithm_by_name
    raise NotImplementedError("Algorithm not supported") from e
NotImplementedError: Algorithm not supported

auth0-python version

4.2.0

Python version

3.10

@basilfx basilfx added the bug This points to a verified bug in the code label Jun 12, 2023
@basilfx
Copy link
Author

basilfx commented Jun 12, 2023

I also believe that piece of code performs a wrong check:

if token is None:
    # Wrap the auth client
    super().__init__(domain, telemetry, timeout, protocol)
else:
    # Wrap the mngtmt client
    super().__init__(
        domain, token, telemetry, timeout, protocol, rest_options
    )

token is the second argument of Wrapper. But it is not the second argument of GetToken (or AuthenticationBase). I use it according to this example (the second argument is not a token).

@adamjmcgrath adamjmcgrath mentioned this issue Jun 22, 2023
3 tasks
@adamjmcgrath
Copy link
Contributor

Thanks for raising this @basilfx! Have created a PR to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants