Skip to main content
 首页 » 编程设计

python之Python 中的 FIWARE OAuth2 身份验证

2025年05月04日8telwanggs

我正在尝试使用 FIWARE 对用户进行身份验证。

它返回 404。因此在步骤 1 本身失败。访问 token url 是什么?任何其他要检查的指针

我已经尝试过 'oauth/access_token', 'oauth/token' 'oauth2/token' 'oauth2/access_token' 的变体。它们似乎都不起作用。

我的代码如下:

import oauth2 as oauth 
 
# OAuth secret into your project's settings.  
consumer = oauth2.Consumer(settings.FIWARE_CLIENT_ID,settings.FIWARE_CLIENT_SECRET) 
client = oauth2.Client(consumer) 
 
access_token_url = 'https://account.lab.fiware.org/oauth2/access_token' 
 
# This is the slightly different URL used to authenticate/authorize. 
authenticate_url = 'https://account.lab.fiware.org/oauth2/authorize' 
 
 
def fiware_login(request): 
# Step 1. Get a request token from FIWARE. 
resp, content = client.request(access_token_url, "GET") 
print resp 
if resp['status'] != '200': 
    print content 
    raise Exception("Invalid response from FIWARE.") 
 
 
# Step 2. Redirect the user to the authentication URL. 
url = "%s?access_token=%s" % (authenticate_url, 
    resp['access_token']) 
 
return HttpResponseRedirect(url) 

请您参考如下方法:

正确的端点是“/oauth2/token”。

也许你应该使用 POST 方法而不是 GET。

有关详细信息,请参阅 https://github.com/ging/fi-ware-idm/wiki/Using-the-FI-LAB-instance