Sha256: a7d28178d363fdde75171f4c4e9723188c69f3cf210d1a5162e5c6a279886305

Contents?: true

Size: 1.47 KB

Versions: 16

Compression:

Stored size: 1.47 KB

Contents

module Doorkeeper
  module OAuth
    module Authorization
      class Token
        attr_accessor :pre_auth, :resource_owner, :token

        def initialize(pre_auth, resource_owner)
          @pre_auth       = pre_auth
          @resource_owner = resource_owner
        end

        def self.access_token_expires_in(server, pre_auth_or_oauth_client)
          if expiration = custom_expiration(server, pre_auth_or_oauth_client)
            expiration
          else
            server.access_token_expires_in
          end
        end

        def issue_token
          @token ||= AccessToken.find_or_create_for(
            pre_auth.client,
            resource_owner.id,
            pre_auth.scopes,
            self.class.access_token_expires_in(configuration, pre_auth),
            false
          )
        end

        def native_redirect
          {
            controller: 'doorkeeper/token_info',
            action: :show,
            access_token: token.token
          }
        end

        private

        def self.custom_expiration(server, pre_auth_or_oauth_client)
          oauth_client = if pre_auth_or_oauth_client.respond_to?(:client)
                           pre_auth_or_oauth_client.client
                         else
                           pre_auth_or_oauth_client
                         end

          server.custom_access_token_expires_in.call(oauth_client)
        end

        def configuration
          Doorkeeper.configuration
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
doorkeeper-4.2.6 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.2.5 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.2.0 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.1.0 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.0.0 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.0.0.rc4 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.0.0.rc3 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.0.0.rc2 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-4.0.0.rc1 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-3.1.0 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-3.0.1 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-2.2.2 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-3.0.0 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-3.0.0.rc2 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-3.0.0.rc1 lib/doorkeeper/oauth/authorization/token.rb
doorkeeper-2.2.1 lib/doorkeeper/oauth/authorization/token.rb