簡體   English   中英

如何使用刷新令牌在 django-oauth-toolkit 上獲取新的訪問令牌?

[英]How to use refresh token to obtain new access token on django-oauth-toolkit?

我在我的 Django 項目中使用django-oauth-toolkit 0.7通過我的網站提供 Oauth2。

我已按照此處的步驟成功獲得訪問令牌,但我無法使用refresh token獲取新的access token (如果訪問令牌已過期)。

我可以通過消費者客戶端獲取access token ,但是如何通過我的 web 站點中的 url 獲取此令牌,因為當我嘗試通過refresh token獲取新的access token時,我無法看到哪些參數將進入我的站點refresh token

我的訪問和刷新令牌是這樣的:

{
  "access_token":"1/fFAGRNJru1FTz70BzhT3Zg",
  "expires_in":3920,
  "token_type":"Bearer",
  "refresh_token":"1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
}

任何幫助將非常感激。

要獲取新的access_token ,通過使用現有的refresh_token您需要將 POST 請求發送到您用來首先獲取令牌的相同 url ( /o/token/ ,假設為默認 url)。 grant_type現在將是refresh_token ,並且您還需要使用您的客戶端憑據進行身份驗證,因為您已獲得了一些憑據。

總結一下: curl -X POST -d "grant_type=refresh_token&client_id=<your_client_id>&client_secret=<your_client_secret>&refresh_token=<your_refresh_token>" http://localhost:8000/o/token/

如果您想了解更多信息,可以查看此鏈接以查看標准的相關部分。

您可以在 POSTMAN 中傳遞 post 請求。 或者試試這個,它對我有用:

curl -X POST -H 'Authorization: Basic your_application_id' -d 'refresh_token=your_refresh_token&grant_type=refresh_token' localhost:3000/o/token

{
    "token_type":"bearer",
    "access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiVlx1MDAxNcKbwoNUwoonbFPCu8KhwrYiLCJpYXQiOjE0NDQyNjI4NjYsImV4cCI6MTQ0NDI2Mjg4Nn0.Dww7TC-d0teDAgsmKHw7bhF2THNichsE6rVJq9xu_2s",
    "expires_in":20,
    "refresh_token":"7fd15938c823cf58e78019bea2af142f9449696a"
}

試試這個鏈接

要通過 URL 從refresh_token獲取新的access_token ,您可以使用以下 URL 並在參數中傳遞數據:

http://127.0.0.1:8000/o/token/?grant_type=refresh_token&refresh_token=<refresh_token_here>&client_id=<your client id here>&client_secret=<your client secret here>

refresh_token的幫助下生成新的access_token后,舊的access_token將過期。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM