omniauth-chatwork 0.1.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b283578d6148059a0bf0d23632db6ec3adfbb1d1
4
+ data.tar.gz: 655378c2a5ba57312af63d63db237d23057b774c
5
+ SHA512:
6
+ metadata.gz: 4c1570a1f2339e71fcf37be3a5395e6dbce826deb757d3390ccaec88a09a69d73ae36d36c5fe65446bf944ef982011d0c13f677b7913defae35712a269152877
7
+ data.tar.gz: b1bcab061bd52c4c8887cffa1820b5eebfd4ad93b5c4008c664f9ba5c59eae269a0cd73758a7c03cf2e9071f47443d51495af3f2f2a448ad3b1ac7bf69d6577d
data/.env.example ADDED
@@ -0,0 +1,6 @@
1
+ CLIENT_ID=
2
+ CLIENT_SECRET=
3
+
4
+ # verbose logging for faraday
5
+ # ref. https://github.com/intridea/oauth2/blob/v1.4.0/lib/oauth2/client.rb#L95
6
+ # OAUTH_DEBUG=true
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in omniauth-chatwork.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # OmniAuth::Chatwork
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/chatwork`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-chatwork'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-chatwork
22
+
23
+ ## Usage
24
+ ```ruby
25
+ use OmniAuth::Builder do
26
+ provider :chatwork, ENV["CLIENT_ID"], ENV["CLIENT_SECRET"]
27
+ # or
28
+ provider :chatwork, ENV["CLIENT_ID"], ENV["CLIENT_SECRET"], scope: ["users.all:read", "rooms.all:read_write", "contacts.all:read_write"]
29
+ end
30
+ ```
31
+
32
+ ## Configuring
33
+ * `scope` : `String` or `Array`
34
+ * A list of permissions you want to request from the user
35
+ * default is `["rooms.all:read_write"]`
36
+ * see Appendix scope list of http://download.chatwork.com/ChatWork_API_Documentation.pdf (en) or http://developer.chatwork.com/ja/oauth.html#secAppendix (ja)
37
+
38
+ ## Auth Hash
39
+ An example auth hash available in `request.env['omniauth.auth']`:
40
+
41
+ ```ruby
42
+ {
43
+ provider: "chatwork",
44
+ uid: 1111111,
45
+ info: {
46
+ name: "sue445",
47
+ email: "sue445@example.com",
48
+ description: "I am cure engineer!",
49
+ image: "https://appdata.chatwork.com/avatar/ico_default_blue.png",
50
+ urls: {
51
+ profile: "http://github.com/sue445"
52
+ }
53
+ },
54
+ credentials: {
55
+ token: "XXXXXXXXXXXXXXXXXXX",
56
+ refresh_token: "XXXXXXXXXXXXXXXXXXX",
57
+ expires_at: 1510504991,
58
+ expires: true
59
+ },
60
+ extra: {
61
+ raw_info: {
62
+ account_id: 1111111,
63
+ room_id: 1111111,
64
+ name: "sue445",
65
+ chatwork_id: "",
66
+ organization_id: 1111111,
67
+ organization_name: "",
68
+ department: "",
69
+ title: "",
70
+ url: "http://github.com/sue445",
71
+ introduction: "I am cure engineer!",
72
+ mail: "",
73
+ tel_organization: "",
74
+ tel_extension: "",
75
+ tel_mobile: "",
76
+ skype: "",
77
+ facebook: "",
78
+ twitter: "",
79
+ avatar_image_url: "https://appdata.chatwork.com/avatar/ico_default_blue.png",
80
+ login_mail: "sue445@example.com"
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+
90
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
+
92
+ ### Run dummy app
93
+ ```bash
94
+ cp .env.example .env
95
+ vi .env
96
+
97
+ bundle exec ruby spec/dummy/app.rb
98
+ ```
99
+
100
+ open https://127.0.0.1:4567/
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/omniauth-chatwork.
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/chatwork"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require "omniauth/chatwork"
@@ -0,0 +1,8 @@
1
+ require "omniauth/chatwork/version"
2
+ require "omniauth/strategies/chatwork"
3
+
4
+ module OmniAuth
5
+ module Chatwork
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Chatwork
3
+ VERSION = "0.1.0.beta1"
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ require "omniauth/strategies/oauth2"
2
+ require "faraday"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Chatwork < ::OmniAuth::Strategies::OAuth2
7
+ DEFAULT_SCOPE = "rooms.all:read_write"
8
+
9
+ option :client_options, {
10
+ site: "https://api.chatwork.com/v2",
11
+ authorize_url: "https://www.chatwork.com/packages/oauth2/login.php",
12
+ token_url: "https://oauth.chatwork.com/token",
13
+ auth_scheme: :basic_auth,
14
+ }
15
+
16
+ uid { raw_info["account_id"] }
17
+
18
+ info do
19
+ # via. https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema
20
+ {
21
+ "name" => raw_info["name"],
22
+ "email" => raw_info["login_mail"],
23
+ "description" => raw_info["introduction"],
24
+ "image" => raw_info["avatar_image_url"],
25
+ "urls" => {
26
+ "profile" => raw_info["url"],
27
+ },
28
+ }
29
+ end
30
+
31
+ extra do
32
+ hash = {}
33
+ hash["raw_info"] = raw_info unless skip_info?
34
+ hash
35
+ end
36
+
37
+ def raw_info
38
+ @raw_info ||= access_token.get("me").parsed || {}
39
+ end
40
+
41
+ # You can pass +scope+ params to the auth request, if you need to set them dynamically.
42
+ # You can also set these options in the OmniAuth config :authorize_params option.
43
+ #
44
+ # For example: /auth/chatwork?scope=rooms.all:read_write
45
+ def authorize_params
46
+ super.tap do |params|
47
+ %w[scope].each do |v|
48
+ if request.params[v]
49
+ params[v.to_sym] = request.params[v]
50
+ end
51
+ end
52
+
53
+ params[:scope] ||= DEFAULT_SCOPE
54
+ params[:scope] = Array(params[:scope]).join(" ")
55
+ end
56
+ end
57
+
58
+ def build_access_token
59
+ verifier = request.params["code"]
60
+ client.auth_code.get_token(verifier, {:redirect_uri => access_token_callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
61
+ end
62
+
63
+ def access_token_callback_url
64
+ # Remove query string from OmniAuth::Strategy#callback_url
65
+ # https://github.com/omniauth/omniauth/blob/v1.7.1/lib/omniauth/strategy.rb#L438-L440
66
+ options[:callback_url] || (full_host + script_name + callback_path)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "omniauth/chatwork/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-chatwork"
8
+ spec.version = OmniAuth::Chatwork::VERSION
9
+ spec.authors = ["sue445"]
10
+ spec.email = ["sue445@sue445.net"]
11
+
12
+ spec.summary = %q{OmniAuth strategy for ChatWork}
13
+ spec.description = %q{OmniAuth strategy for ChatWork}
14
+ spec.homepage = "https://github.com/sue445/omniauth-chatwork"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "omniauth-oauth2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "dotenv"
28
+ spec.add_development_dependency "faraday_curl"
29
+ spec.add_development_dependency "pry-byebug"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "sinatra"
33
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-chatwork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_curl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: OmniAuth strategy for ChatWork
126
+ email:
127
+ - sue445@sue445.net
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".env.example"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/omniauth-chatwork.rb
143
+ - lib/omniauth/chatwork.rb
144
+ - lib/omniauth/chatwork/version.rb
145
+ - lib/omniauth/strategies/chatwork.rb
146
+ - omniauth-chatwork.gemspec
147
+ homepage: https://github.com/sue445/omniauth-chatwork
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">"
163
+ - !ruby/object:Gem::Version
164
+ version: 1.3.1
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.6.11
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: OmniAuth strategy for ChatWork
171
+ test_files: []