2017-10-19 3 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 Unauthorized이됩니다.

두 번째 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 Unauthorized.

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.

관련 문제