lib/doorkeeper/oauth/authorization/token.rb in doorkeeper-5.0.0.rc1 vs lib/doorkeeper/oauth/authorization/token.rb in doorkeeper-5.0.0.rc2
- old
+ new
@@ -3,51 +3,58 @@
module Authorization
class Token
attr_accessor :pre_auth, :resource_owner, :token
class << self
- def access_token_expires_in(server, pre_auth_or_oauth_client, grant_type, scopes)
- if (expiration = custom_expiration(server, pre_auth_or_oauth_client, grant_type, scopes))
- expiration
- else
- server.access_token_expires_in
- end
- end
-
- private
-
- def custom_expiration(server, pre_auth_or_oauth_client, grant_type, scopes)
+ def build_context(pre_auth_or_oauth_client, grant_type, scopes)
oauth_client = if pre_auth_or_oauth_client.respond_to?(:client)
pre_auth_or_oauth_client.client
else
pre_auth_or_oauth_client
end
- context = Doorkeeper::OAuth::Authorization::Context.new(
+
+ Doorkeeper::OAuth::Authorization::Context.new(
oauth_client,
grant_type,
scopes
)
+ end
- server.custom_access_token_expires_in.call(context)
+ def access_token_expires_in(server, context)
+ if (expiration = server.custom_access_token_expires_in.call(context))
+ expiration
+ else
+ server.access_token_expires_in
+ end
end
+
+ def refresh_token_enabled?(server, context)
+ if server.refresh_token_enabled?.respond_to? :call
+ server.refresh_token_enabled?.call(context)
+ else
+ !!server.refresh_token_enabled?
+ end
+ end
+
+ private
end
def initialize(pre_auth, resource_owner)
@pre_auth = pre_auth
@resource_owner = resource_owner
end
def issue_token
+ context = self.class.build_context(
+ pre_auth.client,
+ Doorkeeper::OAuth::IMPLICIT,
+ pre_auth.scopes
+ )
@token ||= AccessToken.find_or_create_for(
pre_auth.client,
resource_owner.id,
pre_auth.scopes,
- self.class.access_token_expires_in(
- configuration,
- pre_auth,
- Doorkeeper::OAuth::IMPLICIT,
- pre_auth.scopes
- ),
+ self.class.access_token_expires_in(configuration, context),
false
)
end
def native_redirect