Sha256: 574442f82cdc49983e79f57de7c82692785565e0f584001394abd54cdcceadc2

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'base64'
require 'oauth2'
require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    # OmniAuth strategy for zoom.us
    class Zoom < OmniAuth::Strategies::OAuth2
      option :name, 'zoom'
      option :client_options, :site => 'https://zoom.us'

      uid { raw_info['id'] }
      extra { {:raw_info => raw_info} }

    protected

      def build_access_token
        params = {
          :grant_type => 'authorization_code',
          :code => request.params['code'],
          :redirect_uri => callback_url
        }
        path = "#{client.options[:token_url]}?#{URI.encode_www_form(params)}"
        headers_secret = Base64.strict_encode64("#{client.id}:#{client.secret}")
        opts = {:headers => {:Authorization => "Basic #{headers_secret}"}}

        res = client.request(:post, path, opts)
        ::OAuth2::AccessToken.from_hash(client, res.parsed)
      end

    private

      def raw_info
        return @raw_info if defined?(@raw_info)

        @raw_info = access_token.get('/v2/users/me').parsed || {}
      rescue StandardError => e
        log(:error, "#{e.class} occured. message:#{e.message}")
        @raw_info = {}
      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-zoom-0.1.1 lib/omniauth/strategies/zoom.rb