Sha256: 82a60b066a9930a58f27f59e6bd3ad2d2eb54d652976d5e714f0b8973559425b

Contents?: true

Size: 999 Bytes

Versions: 7

Compression:

Stored size: 999 Bytes

Contents

require 'bootic_client/strategies/oauth2_strategy'

module BooticClient
  module Strategies

    class Authorized < Oauth2Strategy
      private

      def validate!
        raise ArgumentError, 'options MUST include access_token' unless options[:access_token]
      end

      def get_token
        # The JWT grant must have an expiration date, in seconds since the epoch.
        # For most cases a few seconds should be enough.
        exp = Time.now.utc.to_i + 30

        # Use the "assertion" flow to exchange the JWT grant for an access token
        access_token = auth.assertion.get_token(
          hmac_secret: config.client_secret,
          iss: config.client_id,
          prn: client.options[:access_token],
          aud: 'api',
          exp: exp,
          scope: ''
        )

        access_token.token
      end

      def auth
        @auth ||= OAuth2::Client.new('', '', site: config.auth_host)
      end
    end

  end

  strategies[:authorized] = Strategies::Authorized
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bootic_client-0.0.28 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.27 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.26 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.25 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.24 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.23 lib/bootic_client/strategies/authorized.rb
bootic_client-0.0.22 lib/bootic_client/strategies/authorized.rb