简体   繁体   English

Rails api不会通过devise令牌auth将访问令牌和客户端返回到外部URL

[英]Rails api is not returning access-token and client to external url via devise token auth

I'm having an issue with devise_token_auth returning a client and access-token back to my front end. 我在devise_token_auth返回客户端和访问令牌回到我的前端时遇到问题。 It works fine in my test environment and I get the expected results. 在我的测试环境中,它运行良好,并且得到了预期的结果。 But in my dev environment I am using a external url. 但是在我的开发环境中,我使用的是外部网址。 This is the response I get when I create a session: 这是我创建会话时得到的响应:

 Object {
   "config": Object {
     "adapter": [Function xhrAdapter],
     "baseURL": "http://93ae6a5f.ngrok.io/api/v1",
     "data": "{\"email\":\"test@gmail.com\",\"password\":\"password\"}",
     "headers": Object {
       "Accept": "application/json",
       "Content-Type": "application/json",
     },
     "maxContentLength": -1,
     "method": "post",
     "timeout": 0,
     "transformRequest": Object {
       "0": [Function transformRequest],
     },
     "transformResponse": Object {
       "0": [Function transformResponse],
     },
     "url": "http://93ae6a5f.ngrok.io/api/v1/auth/sign_in",
     "validateStatus": [Function validateStatus],
     "xsrfCookieName": "XSRF-TOKEN",
     "xsrfHeaderName": "X-XSRF-TOKEN",
   },
   "data": Object {
     "data": Object {
       "allow_password_change": false,
       "email": "test@gmail.com",
       "id": 1,
       "image": null,
       "name": null,
       "nickname": null,
       "provider": "email",
       "uid": "test@gmail.com",
       "username": null,
     },
   },
   "duration": 731,
   "headers": Object {
     "cache-control": "public, max-age=0",
     "content-type": "application/json; charset=utf-8",
     "etag": "W/\"0fa41fc630ddb8ffc9b9f9f9b90849b5\"",
     "transfer-encoding": "chunked",
     "vary": "Origin",
     "x-request-id": "320d3bd6-7e94-48b4-8e14-fe434d593b6a",
     "x-runtime": "0.303548",
   },
   "ok": true,
   "originalError": null,
   "problem": null,
   "status": 200,
 }

I went through the devise_token_auth docs and have already added this to my application.rb 我浏览了devise_token_auth文档,并将其添加到我的application.rb

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

Anyone have any thoughts on how to get this working? 有人对如何使它起作用有任何想法吗?

您是否将以下内容添加到控制器中?

include DeviseTokenAuth::Concerns::SetUserByToken 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM