Sha256: a3d87e4c91565188befa297d4ca9b7d228124971608d971eb65b22f289149bcc

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'omniauth/strategies/oauth2'

module OmniAuth
  module Strategies
    class Fiken < OmniAuth::Strategies::OAuth2
      # Give your strategy a name.
      option :name, 'fiken'

      # This is where you pass the options you would pass when
      # initializing your consumer from the OAuth gem.
      option :client_options,
        site: 'https://api.fiken.no/api/v2/',
        authorize_url: 'https://fiken.no/oauth/authorize',
        token_url: 'https://fiken.no/oauth/token',
        connection_opts: {
          headers: {
            user_agent: 'omniauth-fiken',
            accept: 'application/json',
            content_type: 'application/json',
          },
        }

      # The Fiken API requires HTTP Basic Authentication when exchanging the
      # code for a token (i.e. when POSTing to /v1/oauth/token)
      def build_access_token
        options.token_params.merge!(
          headers: { 'Authorization' => basic_auth_header },
        )
        super
      end

      def basic_auth_header
        "Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
      end

      def callback_url
        full_host + script_name + callback_path
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-fiken-0.0.2 lib/omniauth-fiken.rb