Ruby on rails 余烬简单身份验证+;设计投掷405

Ruby on rails 余烬简单身份验证+;设计投掷405,ruby-on-rails,authentication,ember.js,devise,ember-simple-auth,Ruby On Rails,Authentication,Ember.js,Devise,Ember Simple Auth,我使用的堆栈包括Rails和Grape(用于API内容)以及Desive(用于用户内容),以及Ember和Ember CLI以及Ember Simple Auth。我想使用Simple Auth公开的DeviseAuthenticator实现授权。我的登录控制器如下所示: // app/controllers/login.js import Ember from 'ember' export default Ember.Controller.extend({ session: Ember

我使用的堆栈包括Rails和Grape(用于API内容)以及Desive(用于用户内容),以及Ember和Ember CLI以及Ember Simple Auth。我想使用Simple Auth公开的DeviseAuthenticator实现授权。我的登录控制器如下所示:

// 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)
      })
    }
  }
})
以及我的Desive验证器设置:

// 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/']
})
出于开发目的,我已经注释掉了
错误!“401 Unauthorized”,401除非经过身份验证,否则在我的Grape配置中加入一部分(这是另一个问题),只是为了看看它是否有效,但它抛出了以下内容:

POSThttp://localhost:4200/api/v1/users/sign_in 405(不允许使用方法)


我不知道该怎么办,因此希望能得到一些帮助。如果我能从其他文件中发布更多代码,我很乐意告诉我。

发现我的设计路线位于
/users/sign\u in
,不在
/api/v1/users/sign_in

crossOriginWhiteList
不再存在,因为自动授权已被删除-您可以安全地删除它。设置可能应该是
serverTokenEndpoint:'http://localhost:3000/api/v1/users/sign_in“
(端口3000而不是4200)或者您正在使用Ember CLI代理模式?如果您是,那么您的Rails服务器不允许向
serverTokenEndpoint:'/api/v1/users/sign_in'
发送
POST
s请求,这会很奇怪,因为
POST
s实际上应该是唯一发送到该路由的请求。@Marcow我的Rails服务器位于
localhost:4200
。rails和ember都在不同的进程中运行。另外,什么是ember CLI代理模式?ember CLI通常在端口4200上运行,您不能让Rails也在该端口上运行。Rails通常在端口3000上运行。有关代理模式的信息,请参见此处的
ember-service
文档:在这种情况下,是的,我正在使用代理模式来
localhost:3000