lundi 2 novembre 2015

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. Reference resources: http://ift.tt/1k41aJF .
Now my authentification doesn't work at all, because authenticate_with_http_token alway empty, I could not find any problems with it. 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);
      });
    }
  }
})




Aucun commentaire:

Enregistrer un commentaire