steep-keyboard-7095
05/09/2023, 6:05 PMdescope_client.validate_session(session_token)
line with valid inputs whereas locally it works just fine. This could also just be a internet access issue on my end but I wanted to double check here since that route isn't working as expected.square-vr-55083
05/09/2023, 6:09 PMsteep-keyboard-7095
05/09/2023, 6:10 PMsteep-keyboard-7095
05/09/2023, 6:28 PMsquare-vr-55083
05/09/2023, 6:29 PMsteep-keyboard-7095
05/09/2023, 6:33 PMclient = DescopeClient(project_id='')
# Extract the 'Cookie' header from the event
headers = event.get("headers", {})
ds_token = headers.get("authorization", "0 0").split(" ")[1]
print(ds_token)
jwtdict = client.validate_session(session_token=ds_token)
square-vr-55083
05/09/2023, 6:33 PMsteep-keyboard-7095
05/09/2023, 6:35 PMsteep-keyboard-7095
05/09/2023, 6:36 PMsteep-keyboard-7095
05/09/2023, 6:40 PM{
"errorMessage": "{'status_code': 401, 'error_type': 'invalid token', 'error_message': \"Invalid session token: {'status_code': 500, 'error_type': 'invalid public key', 'error_message': 'Unable to validate public key. Public key not found.'}\"}",
"errorType": "AuthException",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 14, in lambda_handler\n jwtdict = client.validate_session(session_token=ds_token)\n",
" File \"/var/task/descope/descope_client.py\", line 186, in validate_session\n return self._auth.validate_session(session_token)\n",
" File \"/var/task/descope/auth.py\", line 528, in validate_session\n 401, ERROR_TYPE_INVALID_TOKEN, f\"Invalid session token: {e}\"\n"
]
}
square-vr-55083
05/09/2023, 6:41 PMsquare-vr-55083
05/09/2023, 6:41 PMsteep-keyboard-7095
05/09/2023, 6:43 PMsquare-vr-55083
05/09/2023, 6:43 PMsquare-vr-55083
05/09/2023, 6:44 PMsquare-vr-55083
05/09/2023, 6:45 PMsteep-keyboard-7095
05/09/2023, 6:45 PMsquare-vr-55083
05/09/2023, 6:45 PMsquare-vr-55083
05/09/2023, 6:45 PMsteep-keyboard-7095
05/09/2023, 6:49 PMsquare-vr-55083
05/09/2023, 7:10 PMsquare-vr-55083
05/09/2023, 7:10 PMsteep-keyboard-7095
05/09/2023, 7:12 PMorange-belgium-27264
orange-belgium-27264
orange-belgium-27264
steep-keyboard-7095
05/09/2023, 7:59 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:02 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:04 PM[ERROR] AuthException: {'status_code': 401, 'error_type': 'invalid token', 'error_message': "Invalid session token: {'status_code': 500, 'error_type': 'invalid public key', 'error_message': 'Unable to validate public key. Public key not found.'}"}
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 13, in lambda_handler
jwtdict = client.validate_session(session_token=ds_token)
File "/var/task/descope/descope_client.py", line 186, in validate_session
return self._auth.validate_session(session_token)
File "/var/task/descope/auth.py", line 528, in validate_session
401, ERROR_TYPE_INVALID_TOKEN, f"Invalid session token: {e}"
[ERROR] AuthException: {'status_code': 401, 'error_type': 'invalid token', 'error_message': "Invalid session token: {'status_code': 500, 'error_type': 'invalid public key', 'error_message': 'Unable to validate public key. Public key not found.'}"} Traceback (most recent call last): File "/var/task/lambda_function.py", line 13, in lambda_handler jwtdict = client.validate_session(session_token=ds_token) File "/var/task/descope/descope_client.py", line 186, in validate_session return self._auth.validate_session(session_token) File "/var/task/descope/auth.py", line 528, in validate_session 401, ERROR_TYPE_INVALID_TOKEN, f"Invalid session token: {e}"
steep-keyboard-7095
05/09/2023, 8:05 PMorange-belgium-27264
DESCOPE_BASE_URI = <https://api.descope.com>
steep-keyboard-7095
05/09/2023, 8:09 PMorange-belgium-27264
URI
not URL
steep-keyboard-7095
05/09/2023, 8:10 PMDESCOPE_BASE_URI = <https://api.descope.com>
steep-keyboard-7095
05/09/2023, 8:10 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:14 PMsteep-keyboard-7095
05/09/2023, 8:15 PMsteep-keyboard-7095
05/09/2023, 8:16 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:35 PMsteep-keyboard-7095
05/09/2023, 8:35 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:36 PMorange-belgium-27264
steep-keyboard-7095
05/09/2023, 8:50 PMERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.
aiohttp 3.8.1 requires charset-normalizer<3.0,>=2.0, but you have charset-normalizer 3.1.0 which is incompatible.
Successfully installed PyJWT-2.6.0 certifi-2023.5.7 cffi-1.15.1 charset-normalizer-3.1.0 cryptography-40.0.2 descope-1.5.0 dnspython-2.3.0 email-validator-1.3.1 idna-3.4 pycparser-2.21 requests-2.28.2 urllib3-1.26.15
But it exits normallyorange-belgium-27264
conda-repo-cli
in our sdksteep-keyboard-7095
05/09/2023, 9:13 PMpip install descope --target ./package
{
"errorMessage": "Unable to import module 'lambda_function': cannot import name 'ObjectIdentifier' from 'cryptography.hazmat.bindings._rust' (unknown location)",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
steep-keyboard-7095
05/09/2023, 9:23 PMERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.
aiohttp 3.8.1 requires charset-normalizer<3.0,>=2.0, but you have charset-normalizer 3.1.0 which is incompatible.
steep-keyboard-7095
05/09/2023, 9:24 PMsteep-keyboard-7095
05/10/2023, 4:27 PMsteep-keyboard-7095
05/10/2023, 4:28 PMsquare-vr-55083
05/10/2023, 4:50 PMsteep-keyboard-7095
05/10/2023, 4:50 PMsteep-keyboard-7095
05/10/2023, 4:51 PMsteep-keyboard-7095
05/10/2023, 5:02 PMsteep-keyboard-7095
05/10/2023, 7:43 PMy", line 8, in <module>
import jwt
File "/opt/python/lib/python3.10/site-packages/jwt/__init__.py", line 1, in <module>
from .api_jwk import PyJWK, PyJWKSet
File "/opt/python/lib/python3.10/site-packages/jwt/api_jwk.py", line 6, in <module>
from .algorithms import get_default_algorithms
File "/opt/python/lib/python3.10/site-packages/jwt/algorithms.py", line 6, in <module>
from .utils import (
File "/opt/python/lib/python3.10/site-packages/jwt/utils.py", line 7, in <module>
from <http://cryptography.hazmat.primitives.asymmetric.ec|cryptography.hazmat.primitives.asymmetric.ec> import EllipticCurve
File "/opt/python/lib/python3.10/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py", line 10, in <module>
from cryptography.hazmat._oid import ObjectIdentifier
File "/opt/python/lib/python3.10/site-packages/cryptography/hazmat/_oid.py", line 7, in <module>
from cryptography.hazmat.bindings._rust import (
pyo3_runtime.PanicException: Python API call failed
ModuleNotFoundError: No module named '_cffi_backend'
thread '<unnamed>' panicked at 'Python API call failed', /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.15.2/src/err/mod.rs:582:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 60, in <module>
main()
File "/var/runtime/bootstrap.py", line 57, in main
awslambdaricmain.main([os.environ["LAMBDA_TASK_ROOT"], os.environ["_HANDLER"]])
File "/var/runtime/awslambdaric/__main__.py", line 21, in main
bootstrap.run(app_root, handler, lambda_runtime_api_addr)
File "/var/runtime/awslambdaric/bootstrap.py", line 389, in run
request_handler = _get_handler(handler)
File "/var/runtime/awslambdaric/bootstrap.py", line 39, in _get_handler
m = importlib.import_module(modname.replace("/", "."))
File "/var/lang/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/var/task/lambda_function.py", line 2, in <module>
from descope import DescopeClient, AuthException
File "/opt/python/lib/python3.10/site-packages/descope/__init__.py", line 10, in <module>
from descope.descope_client import DescopeClient
File "/opt/python/lib/python3.10/site-packages/descope/descope_client.py", line 5, in <module>
from descope.auth import Auth # noqa: F401
File "/opt/python/lib/python3.10/site-packages/descope/auth.py", line 8, in <module>
import jwt
File "/opt/python/lib/python3.10/site-packages/jwt/__init__.py", line 1, in <module>
from .api_jwk import PyJWK, PyJWKSet
File "/opt/python/lib/python3.10/site-packages/jwt/api_jwk.py", line 6, in <module>
from .algorithms import get_default_algorithms
File "/opt/python/lib/python3.10/site-packages/jwt/algorithms.py", line 6, in <module>
from .utils import (
File "/opt/python/lib/python3.10/site-packages/jwt/utils.py", line 7, in <module>
from <http://cryptography.hazmat.primitives.asymmetric.ec|cryptography.hazmat.primitives.asymmetric.ec> import EllipticCurve
File "/opt/python/lib/python3.10/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py", line 10, in <module>
from cryptography.hazmat._oid import ObjectIdentifier
File "/opt/python/lib/python3.10/site-packages/cryptography/hazmat/_oid.py", line 7, in <module>
from cryptography.hazmat.bindings._rust import (
pyo3_runtime.PanicException: Python API call failed
START RequestId: 93f1e34f-39da-4833-89a5-fbbedb4ab2a2 Version: $LATEST
RequestId: 93f1e34f-39da-4833-89a5-fbbedb4ab2a2 Error: Runtime exited with error: exit status 1
Runtime.ExitError
END RequestId: 93f1e34f-39da-4833-89a5-fbbedb4ab2a2
REPORT RequestId: 93f1e34f-39da-4833-89a5-fbbedb4ab2a2 Duration: 4389.90 ms Billed Duration: 4390 ms Memory Size: 128 MB Max Memory Used: 18 MB
square-vr-55083
05/10/2023, 7:51 PMsteep-keyboard-7095
05/10/2023, 9:09 PM"errorMessage": "No module named 'cryptography.hazmat.bindings._openssl'",
But if I use v35.0.0 or higher then I get this error
"errorMessage": "Unable to import module 'lambda_function': cannot import name 'asn1' from 'cryptography.hazmat.bindings._rust' (unknown location)",
steep-keyboard-7095
05/10/2023, 9:46 PMpip install --target ./python/lib/python3.9/site-packages/ descope
then navigate down there: cd python/lib/python3.9/site-packages
and remove the cryptography packages: rm -r cryptography*
rm -r cffi*
rm -r pycparser*
Of course, replace python3.9 with whatever your operating system version of python is (which must match the lambda function)
Finally now that the package is ready, navigate up to the top folder and zip the python folder you created in the first step. Then create a new lambda layer and upload this package to it.
Then to make it work for the lambda function, all you have to do is create the function, go to the bottom and add the 2 layers and then it workssteep-keyboard-7095
05/10/2023, 9:48 PMsquare-vr-55083
05/11/2023, 4:35 AMorange-belgium-27264