[英]Doorkeeper with variable token expiration
I'm using Doorkeeper on my app and now I need to set access_token_expires_in
as variable depending user. 我在应用程序上使用了Doorkeeper ,现在我需要将access_token_expires_in
设置为变量,取决于用户。
This value is stored directly on user model but I can't find any way to create a token with this variable. 此值直接存储在用户模型上,但是我找不到任何使用此变量创建令牌的方法。 Here is a part of my tests (not functional) 这是我测试的一部分(不起作用)
require 'error'
Doorkeeper.configure do
orm :active_record
resource_owner_from_credentials do |routes|
request.params[:user] = {:email => request.params[:username], :password => request.params[:password]}
request.env["devise.allow_params_authentication"] = true
user = User.where(email: params[:username]).first
if user.nil? #|| !user.valid_password?(params[:password])
false
else
access_token_expires_in user.access_token_duration
user
end
end
end
I've this (completely normal) error : 我有这个(完全正常)错误:
NoMethodError (undefined method `access_token_duration' for #<User:0x007fed1c062898>)
I could directly update auth_access_token
with my custom value when it's already created but it's a bit dirty. 如果已经创建了我的自定义值,我可以直接使用它更新auth_access_token
,但是有点脏。
Does anyone know another way to do that? 有人知道另一种方法吗?
Such an easy thing (I didn't restart my server) 如此简单(我没有重新启动服务器)
require 'error'
Doorkeeper.configure do |c|
orm :active_record
resource_owner_from_credentials do |routes|
request.params[:user] = {:email => request.params[:username], :password => request.params[:password]}
request.env["devise.allow_params_authentication"] = true
user = User.where(email: params[:username]).first
if user.nil? #|| !user.valid_password?(params[:password])
false
else
c.access_token_expires_in user.access_token_duration
user
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.