Devise auth / sign_in api不返回访问令牌和客户端 [英] Devise auth/sign_in api not returning access-token and client

查看:82
本文介绍了Devise auth / sign_in api不返回访问令牌和客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将omniauth插件集成到了我的Rails应用程序中。现在我在设计sign_in api时遇到了一些问题。

i have recently integrated omniauth plugin into my rails app. and now i have stuck with some issue in devise sign_in api.

该api不返回访问令牌和客户端信息。

The api is not returning the access-token and client information.

请求有效负载

{""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正常运行,并返回访问令牌和客户端,

Before integrating omniauth , sign_in api was working properly and returning the access-token and client,

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' }


推荐答案

您好,添加此代码#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

这篇关于Devise auth / sign_in api不返回访问令牌和客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆