Sha256: f52264c79c691d4818f8e1ade732d25799ee5e57f66b54e36defbe70af78ae20

Contents?: true

Size: 893 Bytes

Versions: 10

Compression:

Stored size: 893 Bytes

Contents

module Quaderno
  module Helpers
    module Authentication

      def get_authentication(options = {})
        mode = options[:mode] || :production

        local_api_model = options[:api_model]
        url = options[:api_url] || (local_api_model && local_api_model.url) || (mode == :production ? 'https://quadernoapp.com/api/' : 'http://sandbox-quadernoapp.com/api/')

        auth_token = options[:auth_token] || options['auth_token'] || (local_api_model && local_api_model.auth_token)
        access_token = options[:access_token] || options['access_token']

        authentication = { url: url, headers: {}, basic_auth: nil }

        if access_token
          authentication[:headers] = { 'Authorization' => "Bearer #{access_token}" }
        elsif auth_token
          authentication[:basic_auth] = { username: auth_token }
        end

        authentication
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
quaderno-1.14.0 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.13.2 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.13.1 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.13.0 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.5 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.4 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.3 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.2 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.1 lib/quaderno-ruby/helpers/authentication.rb
quaderno-1.12.0 lib/quaderno-ruby/helpers/authentication.rb