简体   繁体   English

如何在额外的 API 服务 Auth0 中获取访问令牌?

[英]How to get access token in additional API Service Auth0?

I am currently using @auth0/nextjs-auth0 to implement auth0 auth.我目前正在使用@auth0/nextjs-auth0来实现auth0 auth。 I have implemented the backend using the nextjs-auth0 start guide.我已经使用 nextjs-auth0 入门指南实现了后端。 However I also have a python API that I want to call from my frontend but I want to get the access token in my Python backend as well.但是,我也有一个 python API 我想从我的前端调用,但我也想在我的 Python 后端获取访问令牌。

What would be the best way to go about this? go 关于这个问题的最佳方法是什么? I do not really want to call my backend api from node api as that would just require me repeating all the methods again in my node api just to call the Python api. I do not really want to call my backend api from node api as that would just require me repeating all the methods again in my node api just to call the Python api. Ideal situation would be to just be able to pass the access token somehow to my Python api.理想的情况是能够以某种方式将访问令牌传递给我的 Python api。

You can pass the same access token to both your node.js and python APIs.您可以将相同的访问令牌传递给 node.js 和 python API。 Just pass the same access token JWT as a bearer token in the Authorization header to both back-end APIs.只需将相同的访问令牌 JWT 作为授权 header 中的不记名令牌传递给两个后端 API。

Both back-end APIs should be configured to trust and authenticate access tokens issued by your specific Auth0 tenant.两个后端 API 都应配置为信任和验证由您的特定 Auth0 租户颁发的访问令牌。 You can usually accomplish this by simply pointing one of the many auth libraries for whatever language you're using (eg PyJWT for Python) to the OIDC metadata endpoint for your Auth0 tenant.您通常可以通过简单地将您使用的任何语言(例如 Python 的PyJWT )的众多身份验证库之一指向您的 Auth0 租户的 OIDC 元数据端点来完成此操作。

see here for how to handle JWTs in Python.请参阅此处了解如何处理 Python 中的 JWT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM