我正在开发一个Rails API,并使用devise_token_auth进行身份验证。当我尝试使用put请求更新密码时,访问
/auth/password
会响应错误401,即未经授权。我的服务器日志显示了以下内容:
开始PUT“/auth/password”处理由DeviseTokenAuth :: PasswordsController#update作为HTML的参数: {"password" =>“[FILTERED]”,“password_confirmation”=>“[FILTERED]”} 无法验证CSRF令牌的真实性已完成401未经授权
routes.rb
mount_devise_token_auth_for 'User', at: 'auth' ,:controllers => { :omniauth_callbacks => 'omniauth' }
视图.html(AngularJS)
<div class="container">
<div class="row">
<div class="row">
<div class="col-xs-6 col-xs-offset-3 que">
<img src="./uploads/img/web-logo.png" class="img-responsive" alt="Logo">
</div>
</div>
<div class="col-xs-12 reset-pas">
<form name="update_pass" ng-submit="updatePassword_controller()" role="form" class="lost_reset_password">
<p class="error_msg" ng-show="update_pass.password_confirmation.$error.passwordVerify">
Passwords are not equal!
</p>
<label>New password</label>
<input type="password" name="password" ng-minlength="8" ng-model="updatePasswordForm.password" required="required" class="form-control">
<span>Minimum 8 Charachters</span>
<br>
<label>Re-enter new password</label>
<input type="password" name="password_confirmation" ng-minlength="8" ng-model="updatePasswordForm.password_confirmation" required="required" class="form-control" password-verify="updatePasswordForm.password" >
<button type="submit" class="btn btn-default" id="reset-submit">Save</button>
</form>
</div>
</div>
</div>
controller.js
$scope.updatePassword_controller = function() {
$auth.updatePassword($scope.updatePasswordForm)
.then(function(resp) {
console.log(resp)
$location.path('/')
})
.catch(function(resp) {
console.log(resp)
});
};
更新 注意 我只遇到了密码更新的问题
更新
我安装了gem 'angular_rails_csrf'
现在只会给出授权错误
而不是csrf攻击错误