File: access_token.rb

package info (click to toggle)
ruby-rack-oauth2 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: ruby: 4,013; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Rack
  module OAuth2
    class AccessToken
      include AttrRequired, AttrOptional
      attr_required :access_token, :token_type
      attr_optional :refresh_token, :expires_in, :scope
      attr_accessor :raw_attributes
      delegate :get, :patch, :post, :put, :delete, to: :http_client

      alias_method :to_s, :access_token

      def initialize(attributes = {})
        (required_attributes + optional_attributes).each do |key|
          self.send :"#{key}=", attributes[key]
        end
        @raw_attributes = attributes
        @token_type = self.class.name.demodulize.underscore.to_sym
        attr_missing!
      end

      def http_client
        @http_client ||= Rack::OAuth2.http_client("#{self.class} (#{VERSION})") do |faraday|
          Authenticator.new(self).authenticate(faraday)
        end
      end

      def token_response(options = {})
        {
          access_token: access_token,
          refresh_token: refresh_token,
          token_type: token_type,
          expires_in: expires_in,
          scope: Array(scope).join(' ')
        }
      end
    end
  end
end

require 'rack/oauth2/access_token/authenticator'
require 'rack/oauth2/access_token/bearer'
require 'rack/oauth2/access_token/mtls'