我正在构建一种与Suunto API一起使用的omniauth策略。对他们的token_url
的请求返回包含user
键/值的响应:
{
"access_token":"ACCESS_TOKEN",
"token_type":"bearer",
"refresh_token":"REFRESH_TOKEN",
"expires_in":86399,
"scope":"workout",
"ukv":"1",
"uk":"SOME_VALUE",
"user":"UID",
"jti":"SOME_VALUE"
}
这应该用作uid
值。
基于the Declarative Configuration docs,我尝试了此操作,但没有运气:
option :fields, [:user]
option :uid_field, :user
这不起作用,因为请求中不存在该字段,它在token_url
响应中:
uid do
request.params[options.uid_field.to_s]
end
The Defining the Callback Phase docs上有关于credentials
的注释,但没有用法示例。
我应该在策略中添加/编辑哪些内容,以使其将令牌请求的响应返回的uid
值设置为user
?
答案 0 :(得分:1)
啊!我想到了。这进入了策略:
uid { raw_info["user"] }
def raw_info
@raw_info ||= access_token
end
在raw_info
中,access_token
是我在问题开头添加的哈希。