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.
crossOriginWhiteList
doesn't exist anymore as auto-authorization was removed - you can safely delete that. – marcoowserverTokenEndpoint: '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 allowPOST
requests toserverTokenEndpoint: '/api/v1/users/sign_in'
which would be strange asPOST
s should actually be the only kind of requests that are ever sent to that route. – marcoowlocalhost:4200
. both rails and ember are running in different processes. also, what's ember CLI proxy mode? – jonaember serve
here for info on proxy mode: ember-cli.com/user-guide/#using-ember-cli – marcoowlocalhost:3000
– jona