2017-10-19 107 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.

相关问题