Sha256: e39d2433af92a26adff4a4f387ca57e8790ab370e29d3a4ba3186e271dee0a60

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'omniauth/strategies/oauth2'

module OmniAuth
  module Strategies
    class Wix < OmniAuth::Strategies::OAuth2
      option :name, 'wix'

      option :client_options, {
        :authorize_url => 'https://www.wix.com/installer/install',
        :token_url => 'https://www.wix.com/oauth/access.json'
      }

      option :provider_ignores_state, true

      uid { request.params["instanceId"] }
      
      def client
        ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options)) do |b|
          b.request :json
          b.adapter Faraday.default_adapter
        end
      end

      def authorize_params
        super.tap do |params|
          params["redirectUrl"] = callback_url
          params["appId"] = options[:client_id]
          params["token"] = request.params["token"]
        end
      end
      
      def callback_url
        full_host + script_name + callback_path
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-wix-0.1.2 lib/omniauth/strategies/wix.rb