【问题标题】:Ember Simple Auth + Devise throws 405Ember Simple Auth + Devise 抛出 405
【发布时间】:2016-01-08 21:13:32
【问题描述】:

我正在使用由 Rails 和 Grape(用于 API 内容)和 Devise(用于用户内容)以及 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)
      })
    }
  }
})

和我的 Devise 身份验证器设置:

// 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/']
})

出于开发目的,我在我的 Grape 配置中注释掉了 error! "401 Unauthorized", 401 unless authenticated 部分(虽然这是另一个问题)只是为了看看它是否有效,但它抛出了这个:

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

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

【问题讨论】:

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

标签: ruby-on-rails authentication ember.js devise ember-simple-auth


【解决方案1】:

发现我的设计路线在/users/sign_in,而不是/api/v1/users/sign_in

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多