我只想为每个用户设置一次令牌,您知道如何检查我的令牌是否已设置吗?
这里是我的控制器:
def connexion
code = request.params[:code]
@decoded_code = URI.decode(code)
@id_connection = request.params[:id_connection]
@token = HTTParty.post('https://test-sandbox/auth/token/access',
body: {
client_id: XXXXXX,
client_secret: "YYYYYYYYYYYYYYYYY",
code: @decoded_code
}
)
end
如果返回页面并重新设置令牌,则会出现以下错误:您已经为此用户获得了access_token
您可以使用||=
运算符设置令牌,如果未设置,将尝试获取令牌
@token ||= HTTParty.post('https://test-sandbox/auth/token/access',
body: {
client_id: XXXXXX,
client_secret: "YYYYYYYYYYYYYYYYY",
code: @decoded_code
}
)