【发布时间】:2016-03-28 16:22:38
【问题描述】:
我们正在使用 Ember 2.2.3 前端、Rails 4.2.5 和 Postgres 5.7 为学校项目构建 WebApp。我们遇到了身份验证问题,找不到相关的解决方案。我们认为 ember 应该将我们的电子邮件和密码编码为 JSON 以进行身份验证,Rails 期望 JSON 对象用于验证并返回令牌。但实际发生的是 Ember 正在发送电子邮件和密码的 application/x-www-form-urlencoded 版本,因此 Rails 将抛出 415 Unsupported Media Type Error。我们按照本教程进行身份验证:
http://romulomachado.github.io/2015/09/28/using-ember-simple-auth-with-devise.html
Ember 中有没有办法将此编码更改为 application/json?或者我们可以更改 Rails 以接受 application/x-www-form-urlencoded?
这是我们当前的身份验证请求标头:
POST /users/sign_in HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 63
Accept: application/json, text/javascript
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:4200/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
【问题讨论】:
标签: ruby-on-rails json authentication ember.js devise