0
votes

I'm using a stack consisting of Rails with Grape (for API stuff) and Devise (for user stuff), and Ember with Ember CLI and Ember Simple Auth. I want to implement authorization using the DeviseAuthenticator exposed by Simple Auth. My login controller looks like this:

// app/controllers/login.js

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 => {
        console.log(reason.error || reason)
      })
    }
  }
})

and my Devise authenticator setup:

// app/authenticators/devise.js

import Devise from 'ember-simple-auth/authenticators/devise'

export default Devise.extend({
  serverTokenEndpoint: 'http://localhost:4200/api/v1/users/sign_in',
  resourceName: 'user',
  crossOriginWhiteList: ['http://localhost:4200/']
})

For development purposes, I've commented out the error! "401 Unauthorized", 401 unless authenticated part in my Grape config (that's another problem though) just to see if it even works, but it throws this:

POST http://localhost:4200/api/v1/users/sign_in 405 (Method Not Allowed)

I have no idea what to do, and as such would appreciate some help. If I can post more code from other files, I'd be happy to, just tell me.

1
crossOriginWhiteList doesn't exist anymore as auto-authorization was removed - you can safely delete that.marcoow
The setting should probably be serverTokenEndpoint: 'http://localhost:3000/api/v1/users/sign_in' (port 3000 instead of 4200) or are you using Ember CLI proxy mode? If you are then your Rails server doesn't allow POST requests to serverTokenEndpoint: '/api/v1/users/sign_in' which would be strange as POSTs should actually be the only kind of requests that are ever sent to that route.marcoow
@marcoow my rails server is at localhost:4200. both rails and ember are running in different processes. also, what's ember CLI proxy mode?jona
Ember CLI usually runs on port 4200 and you cannot have Rails running on that port as well. Rails usually runs on port 3000. See the docs for ember serve here for info on proxy mode: ember-cli.com/user-guide/#using-ember-climarcoow
in that case, yes, i am using the proxy mode to localhost:3000jona

1 Answers

0
votes

Found out that my devise routes are at /users/sign_in, not at /api/v1/users/sign_in.