require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Wunderlist < OmniAuth::Strategies::OAuth2
      option :name, 'wunderlist'

      option :client_options, {
        site: "https://a.wunderlist.com/api",
        authorize_url: "https://provider.wunderlist.com/login/oauth/authorize",
        token_url: "https://provider.wunderlist.com/login/oauth/access_token"
      }

      uid { raw_info['id'] }

      extra do
        {:raw_info => raw_info}
      end

      def raw_info
        access_token.options[:mode] = :query
        access_token.options[:param_name] = :access_token
        @raw_info ||= access_token.get('/1/user.json').parsed
      end

    end
  end
end
require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Wunderlist < OmniAuth::Strategies::OAuth2
      option :name, 'wunderlist'
      option :provider_ignores_state, true

      option :client_options, {
        site: "https://a.wunderlist.com/api",
        authorize_url: "https://provider.wunderlist.com/login/oauth/authorize",
        token_url: "https://provider.wunderlist.com/login/oauth/access_token",
        connection_opts: {
          headers: {
            'Accept' => 'application/json',
            'Content-Type' => 'application/json',
          }
        }
      }

      def request_phase
        redirect client.auth_code.authorize_url
      end

      uid { raw_info['id'] }

      info do
        {
          email: raw_info['email'],
          name: raw_info['name']
        }
      end

      extra do
        { raw_info: raw_info }
      end

      def raw_info
        access_token.options[:mode] = :query
        @raw_info ||= access_token.get('/api/v1/user', {
          headers: {
            'X-Client-ID' => ENV['CLIENT_ID'],
            'X-Access-Token' => access_token.token
          }
        }).parsed
      end
    end
  end
end
Fix headers for token and info retrieval
Fix headers for token and info retrieval
