def get_token(params, access_token_opts={}, access_token_class=AccessToken)
      opts = {:raise_errors => options[:raise_errors],
              :parse => params.delete(:parse)}
      if options[:token_method] == :post
        headers = params.delete(:headers)
        opts[:body] = params
        opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
        opts[:headers].merge!(headers) if headers
      else
        opts[:params] = params
      end
      response = request(options[:token_method], token_url, opts)

      if @jwt_secret.nil?
        # Verify state in the response matches the one in the session
        if response.state != @state
          raise ::OmniAuth::Strategies::OAuth2::CallbackError.new(nil,
                                                                  :csrf_detected)
        end
      else
        if JWT.decode(response.state, @jwt_secret)[0]['state'].nil?
          raise ::OmniAuth::Strategies::OAuth2::CallbackError.new(nil,
                                                                  :csrf_detected)
        end
      end

      # error = Error.new(response)
      # fail(error) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])

      provider_client = ::Oauthio::Client.new(@id, @secret, {:site => @site})
      access_token_class.from_hash(provider_client,
                                   response.merge(access_token_opts))
    end
def get_token(params, access_token_opts={}, access_token_class=AccessToken)
      opts = {:raise_errors => options[:raise_errors],
              :parse => params.delete(:parse)}
      if options[:token_method] == :post
        headers = params.delete(:headers)
        opts[:body] = params
        opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
        opts[:headers].merge!(headers) if headers
      else
        opts[:params] = params
      end
      response = request(options[:token_method], token_url, opts)

      if @jwt_secret.nil?
        # Verify state in the response matches the one in the session
        if response.state != @state
          raise ::OmniAuth::Strategies::OAuth2::CallbackError.new(nil,
                                                                  :csrf_detected)
        end
      else
        if JWT.decode(response.state, @jwt_secret)[0]['state'].nil?
          raise ::OmniAuth::Strategies::OAuth2::CallbackError.new(nil,
                                                                  :csrf_detected)
        end
      end

      # error = Error.new(response)
      # fail(error) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])

      provider_client = ::Oauthio::Client.new(@id, @secret, {:site => @site})
      access_token_class.from_hash(provider_client,
                                   response.merge(access_token_opts))
    end
Initializes an AccessToken by making a request to the token endpoint

 @param [Hash] params a Hash of params for the token endpoint
 @param [Hash] access token options, to pass to the AccessToken object
 @param [Class] class of access token for easier subclassing OAuth2::AccessToken
 @return [AccessToken] the initalized AccessToken