我最近在我的rails应用程序中集成了omniauth插件。现在我在设计sign_in api中遇到了一些问题。
api没有返回访问令牌和客户端信息。
请求有效负载
{""email":"testuser@gmail.com","password":"test123"}
请求标题
POST /auth/sign_in HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 95
Cache-Control: max-age=0
Accept: application/json, text/plain, */*
Origin: http://localhost:3000
If-Modified-Since: 0
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:3000/md
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: _my-app_session=f9cbfc20c86a7c21490b6f947b99dab7; auth_headers=%7B%7D
回复标题
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
Etag: "d6dcd0e9690ab0f97a38227f8c8d00a2"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: c906dc68-5bfb-47db-ad9b-c51ccc9774c5
X-Runtime: 0.329334
Server: WEBrick/1.3.1 (Ruby/2.1.8/2015-12-16)
Date: Fri, 17 Jun 2016 17:20:50 GMT
Content-Length: 835
Connection: Keep-Alive
在集成omniauth之前,sign_in api正常工作并返回访问令牌和客户端,
Using devise 3.5.10
Using devise_invitable 1.6.0
Using devise_token_auth 0.1.29
应用程序控制器
class ApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
layout false
before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :load_client
skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
答案 0 :(得分:2)
您好,请添加此代码#config/application.rb
为我工作
gem 'rack-cors', :require => 'rack/cors'
module YourApp
class Application < Rails::Application
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*',
:headers => :any,
:expose => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
:methods => [:get, :post, :options, :delete, :put]
end
end
end
end