Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from koshilife/develop
Browse files Browse the repository at this point in the history
release v0.1.0
  • Loading branch information
koshilife authored Jul 6, 2020
2 parents 73073d1 + ffbc825 commit 6364340
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- Initial release
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth-zoom/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Omniauth
module Zoom
VERSION = '0.0.1'
VERSION = '0.1.0'
end
end
39 changes: 32 additions & 7 deletions lib/omniauth/strategies/zoom.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
# 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] }

extra do
{ 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
1 change: 1 addition & 0 deletions omniauth-zoom.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions test/omniauth/zoom_test.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6364340

Please sign in to comment.