2016-12-01 59 views
1

我有麻煩恢復與devise_token_auth密碼。和Angular2-Token。我成功地通過鏈接接收電子郵件以更新密碼。但是,在提交新密碼時,我收到了401未經授權的回覆。設計令牌認證/角度2令牌,更新密碼,已完成401未授權

前端。我得到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 
    ); 
    } 

後端響應。

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) 

在電子郵件中我得到以下令牌的鏈接:reset_password_token=HneZDoKTMCLF3_SLfnxy
當我訪問該鏈接時,用戶記錄獲取具有以下屬性更新:

reset_password_token: "aa3cba76c7b1d8f78cde6856f43e1cce57f5fc8e5301842733de677eff909bc1" 
tokens: {} 

然後在瀏覽器網址我得到以下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

我最近面臨類似的挑戰,這就是我解決問題的方法。

爲您的後端公開'訪問令牌','過期','令牌類型','uid','客戶端'。檢查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

E.g.如果您的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) %>