2017-10-19 105 views
0

我想改變用戶的密碼,使用Devise Token Auth gem。但有些參數我不知道它是否是好的,因爲我從數據庫中提取它們。具體來說,從我的用戶表中的令牌列。如何使用Devise Token Auth通過API更改密碼? Rails 5

這是我與他們各自的報頭的請求,根據什麼文件告訴我:

PUT /auth/password HTTP/1.1 
Host: localhost 
Content-Type: application/json;charset=utf-8 
token-type: Bearer 
access-token: $2a$10$d6b2GP5N3WT4/fR62S1VL.kiLx9w0YA6Rb5aVYQtXMBPImLx9ix2i 
client: -Z2_wBWzH1GHiAjCAaHAKA 
expiry: 1509654584 
uid: [email protected] 

password=123456789&password_confirmation=123456789 

這是我的用戶表中的令牌列對應於我的用戶與電子郵件[email protected]

{ 
    "oJ7t-1kXUFsde9J_euKuZA":{ 
     "token":"$2a$10$cYAP0ZVndFJz9JUK4tvoOuc96k/JBtgmSyn0cmwvWwy0o.J0XOtKW", 
     "expiry":1509642442, 
     "last_token":"$2a$10$Boy8Yp2Znb0uOS9tt/3KYum7PX/Jjmb.Igzo5GUs4tDRCejDU5bya", 
     "updated_at":"2017-10-19T12:07:22.356-05:00" 
    }, 
    "-Z2_wBWzH1GHiAjCAaHAKA":{ 
     "token":"$2a$10$d6b2GP5N3WT4/fR62S1VL.kiLx9w0YA6Rb5aVYQtXMBPImLx9ix2i", 
     "expiry":1509654584, 
     "last_token":"$2a$10$qFTq5JqGUBXayXODsKUSROjjw.TrFYVGtf.EEULCzRWIhMa79ycZS", 
     "updated_at":"2017-10-19T15:29:44.204-05:00" 
    } 
} 

但是,我的請求的結果總是我得到401未授權

我正在使用第二個json對象,其中我把作爲客戶端參數和令牌屬性的密鑰放在我的請求中,通過PUT將其作爲我的access_token參數。

我正在使用我設置的參數正確地執行我的請求嗎? O如何獲取客戶端和訪問令牌參數?

回答

0

也許這可以幫助你的,文檔包括following infos

帳戶更新。此路線將更新現有用戶的帳戶設置。默認的接受參數是password和password_confirmation,但可以使用devise_parameter_sanitizer系統自定義。如果config.check_current_password_before_update設置爲:attributes,則在任何更新之前檢查current_password參數,如果它設置爲:password,則只有在請求更新用戶密碼時,纔會檢查current_password參數。

enter image description here

所以我想知道,你在你設計出應對包括此強PARAMS聲明爲edit action

但仍然沒有任何解釋說它正在返回401未授權

401 Unauthorized (RFC 7235) Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.[33] 401 semantically means "unauthenticated",[34] i.e. the user does not have the necessary credentials. Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain) and that specific address is refused permission to access a website.

相關問題