2016-12-01 1 views
1

devise_token_auth로 암호를 복구하는 데 문제가 있습니다. Angular2-Token이 있습니다. 비밀번호를 업데이트하는 링크가있는 이메일을 성공적으로 수신했습니다. 하지만 새 비밀번호를 제출할 때 401 Unauthorized 응답이 표시됩니다.Devise Token Auth/Angular2-Token, 암호 업데이트, 완료 401 Unauthorized

프런트 엔드. URL에서 토큰을 가져 오는 중 urlParams.get('token')

onPasswordUpdate() { 
    let token = this.urlParams.get('token'); 
    var obj = Object.assign(this._updatePasswordData, { reset_password_token: token }) 
    this._tokenService.patch('auth/password/', obj).subscribe(
     res => res, 
     error => error 
    ); 
    } 

백 엔드 응답. 브라우저 URL에 다음

reset_password_token: "aa3cba76c7b1d8f78cde6856f43e1cce57f5fc8e5301842733de677eff909bc1" 
tokens: {} 

: 내가 링크를 방문 할 때 reset_password_token=HneZDoKTMCLF3_SLfnxy
는, 사용자 레코드는 다음 속성으로 업데이트되는 : 나는 다음 토큰을 얻을 이메일의 링크에서

Started PATCH "/api/auth/password/" for 127.0.0.1 at 2016-12-01 21:17:48 +0100 
Processing by DeviseTokenAuth::PasswordsController#update as JSON 
    Parameters: {"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"} 
Completed 401 Unauthorized in 1ms (Views: 0.4ms | ActiveRecord: 0.0ms) 

다음을 얻습니다. token=agejaip2SqOp9nvwE1GAHQ&uid
다음 사용자 기록은 다음 속성으로 업데이트됩니다.

... 
reset_password_token: "HneZDoKTMCLF3_SLfnxy", 
tokens: {"pv9i1BDTM29ezep0KSPzpA"=>{"token"=>"$2a$10$cS9gbe9UBICcgphZHRAENOMS6NlEe0Em1cNufY3LSRTPE.hRMabvi", "expiry"=>1481834221}} 
... 

URL에 다시 표시되는 토큰이 올바르지 않은 것 같습니다.
그 누구나 아이디어가 있습니까?

죄송합니다. 설명하기가 조금 어렵습니다.
많은 감사.

레일 (4.2.4)
devise_token_auth (0.1.34)
고안은 (= 3.5.1)
angular2 토큰 : 0.2.0-beta.1는

답변

0

I 최근 유사한 문제에 직면 이것이 내가 어떻게 그것을 해결했는지.

백엔드에 'access-token', 'expiry', 'token-type', 'uid', 'client'를 노출하십시오. herehere

config.middleware.use Rack::Cors do 
    allow do 
     origins '*' 
     resource '*', 
      :headers => :any, 
      :expose => ['access-token', 'expiry', 'token-type', 'uid', 'client'], 
      :methods => => [:get, :post, :options, :delete, :put, :patch] 
    end 
end 

path: /password, method: POST 당신의 REDIRECT_URL를 설정하십시오. 정보 확인 here

reset_password_instructions.html.erb가 api GET/auth/password/edit를 가리 키도록 수정해야합니다. 자세한 내용은 here.

예. 귀하의 API가 API 네임 스페이스 아래에있는 경우 :

<%= link_to 'Change my password', edit_api_user_password_url(reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s) %>

관련 문제