简体   繁体   English

更新后的Ember简单身份验证(Devise),authenticate_with_http_token始终为空

[英]Ember Simple Auth (Devise) after update, authenticate_with_http_token alway empty

I did an update from 0.7.2 to 1.0.1 with ember-simple-authfor for devise. 我使用ember-simple-authfor进行了从0.7.2到1.0.1的更新。 Reference resources: https://github.com/jimbeaudoin/ember-simple-auth-devise-example . 参考资源: https : //github.com/jimbeaudoin/ember-simple-auth-devise-example
Now my authentification doesn't work at all, because authenticate_with_http_token alway empty, I could not find any problems with it. 现在我的身份验证根本不起作用,因为authenticate_with_http_token始终为空,因此我找不到任何问题。 Do you have an idea ? 你有想法吗 ? Thanks. 谢谢。

Version: 版:

Ember: 2.1.0
Ember Simple Auth: 1.0.1
Rails: 4.2.4
Devise: 3.5.2
No Ember data

Rails: 扶手:

class Api::SessionsController < Devise::SessionsController
  skip_before_action :authenticate_user_from_token!
  skip_before_action :verify_authenticity_token

  def create
    respond_to do |format|
      format.html { super }
      format.json do
        self.resource = warden.authenticate!(auth_options)
        sign_in(resource_name, resource)
        data = {
          token: self.resource.authentication_token,
          email: self.resource.email
        }
        render json: data, status: 201
      end
    end
  end
end


class Api::BaseController < ApplicationController
  respond_to :json
  before_action :authenticate_user_from_token!

  # Enter the normal Devise authentication path,
  # using the token authenticated user if available
  before_action :authenticate_user!

  private

  def authenticate_user_from_token!
    authenticate_with_http_token do |token, options|
      user_email = options[:email].presence
      user = user_email && User.unscoped.find_by_email(user_email)
      if user && Devise.secure_compare(user.authentication_token, token)
        sign_in user, store: false
      end      
    end  
  end

end

Ember: 烬:
login-controller: 登录控制器:

import Ember from 'ember';

export default Ember.Controller.extend({
  session: Ember.inject.service('session'),

  actions: {
    authenticate() {
      let { identification, password } = this.getProperties('identification', 'password');
      this.get('session').authenticate('authenticator:devise', identification, password).catch((reason) => {
        this.set('errorMessage', reason.error);
      });
    }
  }
})

ember model: 余烬模型

import Ember from 'ember';
import PromiseArray from './promise-array';
import PromiseObject from './promise-object';

var Account = Ember.Object.extend({
  ...
})

Account.reopenClass({
  _find() {
    return $.get("/api/account.json").then(obj => {
      return this.create(obj.user);
    })
  },

  find() {
    return PromiseObject.create({promise: this._find()});
  }
})

export default Account;

after login route: 登录后的路线:

import Ember from 'ember';
import Account from '../models/account';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  model: function() {
    return Account.find()
  }
})

I think what's failing for you is authorization of requests following the initial login request? 我认为对您来说失败的是在初始登录请求之后对请求的授权? Do you authorize outgoing requests anywhere in your Ember app? 您是否在Ember应用中的任何地方授权传出请求?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM