diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3fafbcd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 + +- Initial release diff --git a/README.md b/README.md index b6d04ab..8d4cd4c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializ ```ruby Rails.application.config.middleware.use OmniAuth::Builder do - provider :zoom, "API_KEY", "API_SECRET" + zoom_scopes = %i[user:read meeting:read meeting:write] + provider :zoom, zoom_client_id, zoom_client_secret, :scope => zoom_scopes.join(',') end ``` @@ -42,7 +43,51 @@ Replace `"API_KEY"` and `"API_SECRET"` with the appropriate values you obtained The auth hash `request.env['omniauth.auth']` would look like this: ```js -TODO +{ + "result": { + "provider": "zoom", + "uid": "KdYKjnimT4KPd8FFgQt9FQ", + "info": {}, + "credentials": { + "token": "ACCESS_TOKEN", + "refresh_token": "REFRESH_TOKEN", + "expires_at": 1594035991, + "expires": true + }, + "extra": { + "raw_info": { + "id": "KdYKjnimT4KPd8FFgQt9FQ", + "first_name": "Jane", + "last_name": "Dev", + "email": "jane.dev@email.com", + "type": 2, + "role_name": "Owner", + "pmi": 1234567890, + "use_pmi": false, + "vanity_url": "https://janedevinc.zoom.us/my/janedev", + "personal_meeting_url": "https://janedevinc.zoom.us/j/1234567890", + "timezone": "America/Denver", + "verified": 1, + "dept": "", + "created_at": "2019-04-05T15:24:32Z", + "last_login_time": "2019-12-16T18:02:48Z", + "last_client_version": "4.6.12611.1124(mac)", + "pic_url": "https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837", + "host_key": "533895", + "jid": "kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us", + "group_ids": [], + "im_group_ids": [ + "3NXCD9VFTCOUH8LD-QciGw" + ], + "account_id": "gVcjZnYYRLDbb_MfgHuaxg", + "language": "en-US", + "phone_country": "US", + "phone_number": "+1 1234567891", + "status": "active" + } + } + } +} ``` ## Contributing diff --git a/lib/omniauth-zoom/version.rb b/lib/omniauth-zoom/version.rb index 6d07cec..432e95f 100644 --- a/lib/omniauth-zoom/version.rb +++ b/lib/omniauth-zoom/version.rb @@ -2,6 +2,6 @@ module Omniauth module Zoom - VERSION = '0.0.1' + VERSION = '0.1.0' end end diff --git a/lib/omniauth/strategies/zoom.rb b/lib/omniauth/strategies/zoom.rb index 1d889b5..9f3474d 100644 --- a/lib/omniauth/strategies/zoom.rb +++ b/lib/omniauth/strategies/zoom.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true +require 'base64' +require 'oauth2' require 'omniauth-oauth2' module OmniAuth module Strategies class Zoom < OmniAuth::Strategies::OAuth2 option :name, 'zoom' - option :client_options, site: 'https://zoom.us', - authorize_url: '/oauth/authorize', - token_url: '/oauth/token' + option :client_options, site: 'https://zoom.us' uid { raw_info[:id] } @@ -16,16 +16,41 @@ class Zoom < OmniAuth::Strategies::OAuth2 { raw_info: raw_info } end - def raw_info - return @raw_info unless @raw_info.nil? + protected - res = access_token.get '/v2/users/me' - @raw_info = JSON.parse(res.body, symbolize_names: true) + def build_access_token + params = { + grant_type: 'authorization_code', + code: request.params['code'], + redirect_uri: callback_url + } + path = "#{client.options[:token_url]}?#{params.to_query}" + token = Base64.strict_encode64("#{client.id}:#{client.secret}") + opts = { headers: { Authorization: "Basic #{token}" } } + + response = client.request(:post, path, opts) + access_token_opts = response.parsed.merge(deep_symbolize(options.auth_token_params)) + ::OAuth2::AccessToken.from_hash(client, access_token_opts).tap do |access_token| + if access_token.respond_to?(:response=) + access_token.response = response + end + end end def callback_url full_host + script_name + callback_path end + + def raw_info + return @raw_info unless @raw_info.nil? + + res = access_token.get('/v2/users/me') + @raw_info = JSON.parse(res.body, symbolize_names: true) + rescue StandardError => e + logger = OmniAuth.config.logger + logger&.debug("#{self.class}.#{__method__} #{e.class} occured. message:#{e.message}") + @raw_info = {} + end end end end diff --git a/omniauth-zoom.gemspec b/omniauth-zoom.gemspec index 9c75a1f..5e9c63f 100644 --- a/omniauth-zoom.gemspec +++ b/omniauth-zoom.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] + spec.add_runtime_dependency 'oauth2', '~> 1.4.4' spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.6.0' spec.add_development_dependency 'bundler', '~> 2.1' diff --git a/test/omniauth/zoom_test.rb b/test/omniauth/zoom_test.rb index d8fe13d..288b858 100644 --- a/test/omniauth/zoom_test.rb +++ b/test/omniauth/zoom_test.rb @@ -1,8 +1,9 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class Omniauth::ZoomTest < Minitest::Test def test_that_it_has_a_version_number refute_nil ::Omniauth::Zoom::VERSION end - end diff --git a/test/test_helper.rb b/test/test_helper.rb index 48f4fbf..b107710 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'simplecov' SimpleCov.start