ruby-on-rails - Rails api 未通过设计令牌身份验证将访问令牌和客户端返回到外部 url
问题描述
我在将devise_token_auth
客户端和访问令牌返回到前端时遇到问题。它在我的测试环境中运行良好,我得到了预期的结果。但在我的开发环境中,我使用的是外部 url。这是我创建会话时得到的响应:
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,
}
我浏览了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
有人对如何使它工作有任何想法吗?
解决方案
您是否将以下内容添加到您的控制器?
include DeviseTokenAuth::Concerns::SetUserByToken
推荐阅读
- keras - 训练后如何计算 BiGAN 鉴别器损失
- flutter - Flutter 无法更新动态 TextEditingController 文本
- python - ValueError:Series.replace 不能使用 dict-value 和 non-None to_replace
- laravel - Laravel:更新数据时在 null 上调用成员函数 getClientOriginalName()
- javascript - 在 Next.js 中连接到 Google 电子表格时出错
- css - 如何修改 CSS 文本动画
- linux - 如何查看我在 linux 共享虚拟主机中可用和使用的配额大小?如果我无权访问“配额”命令
- python - 我的 python Minecraft 副本有问题
- mysql - 如何使用 where 条件计算值,我们可以根据其他表日期放置开始日期和结束日期
- python - 如何让docker容器连续运行?