Sha256: 1900eaeb3df146f9672e884968c04892c38a0dce7d89a24aef07f6f3d91c14ea

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module OmniAuth
  module Strategies
    class Datadog < OmniAuth::Strategies::OAuth2
      CLIENT_OPTIONS = {
        site: 'https://app.datadoghq.com',
        authorize_url: 'oauth2/v1/authorize',
        token_url: 'oauth2/v1/token',
        auth_scheme: :request_body
      }

      VALID_DOMAINS = [
        'datadoghq.eu',
        'datadoghq.com'
      ]

      option :client_options, CLIENT_OPTIONS
      option :pkce, true

      uid do
        raw_info['dd_oid']
      end

      info do
        raw_info
      end

      def raw_info
        @raw_info ||= request.params.slice('dd_org_name', 'dd_oid', 'site')
      end

      def callback_url
        full_host + callback_path
      end

      def build_access_token
        verifier = request.params["code"]
        client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
      end

      # Datadog has a few different domains.
      def client
        client_options = options.client_options
        client_options['site'] = request.params['site'] if request.params['site'] && VALID_DOMAINS.any? { |d| request.params['site'].end_with?(d) }
        ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(client_options))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-datadog-0.1.0 lib/omniauth/strategies/datadog.rb