omniauth-zaif 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +80 -0
- data/LICENSE +21 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/lib/omniauth-zaif.rb +2 -0
- data/lib/omniauth-zaif/version.rb +5 -0
- data/lib/omniauth/strategies/zaif.rb +53 -0
- data/omniauth-zaif.gemspec +23 -0
- data/spec/omniauth/strategies/zaif_spec.rb +77 -0
- data/spec/spec_helper.rb +20 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd1642221a14a8a5b3e08a451f9db55f10dfba1a
|
4
|
+
data.tar.gz: 2d133d3f13819fef15d7a91f4119b7ecdf4a297a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4387ea73ca63f63527c6d6972ff5b65daa938de7a8222127193a4d5b237218324e468bae930e1eeef4ec5ce80e4100cf3a79b3568d2c1025fc894c78af983a22
|
7
|
+
data.tar.gz: 95f8404c38c7480e0d2347e6544374df5bb7e753c534465689731c60df7223e8ffaeeeedd8f90eaed1b7006465948babb5ce90e8538beef84af71a643485a0fa
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-zaif (0.0.1)
|
5
|
+
json (~> 1.3)
|
6
|
+
omniauth-oauth2 (~> 1.3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.1.5)
|
17
|
+
faraday (0.12.2)
|
18
|
+
multipart-post (>= 1.2, < 3)
|
19
|
+
hashdiff (0.3.6)
|
20
|
+
hashie (3.5.6)
|
21
|
+
json (1.8.6)
|
22
|
+
jwt (1.5.6)
|
23
|
+
multi_json (1.12.2)
|
24
|
+
multi_xml (0.6.0)
|
25
|
+
multipart-post (2.0.0)
|
26
|
+
oauth2 (1.4.0)
|
27
|
+
faraday (>= 0.8, < 0.13)
|
28
|
+
jwt (~> 1.0)
|
29
|
+
multi_json (~> 1.3)
|
30
|
+
multi_xml (~> 0.5)
|
31
|
+
rack (>= 1.2, < 3)
|
32
|
+
omniauth (1.6.1)
|
33
|
+
hashie (>= 3.4.6, < 3.6.0)
|
34
|
+
rack (>= 1.6.2, < 3)
|
35
|
+
omniauth-oauth2 (1.3.1)
|
36
|
+
oauth2 (~> 1.0)
|
37
|
+
omniauth (~> 1.2)
|
38
|
+
public_suffix (3.0.0)
|
39
|
+
rack (2.0.3)
|
40
|
+
rack-test (0.7.0)
|
41
|
+
rack (>= 1.0, < 3)
|
42
|
+
rake (12.0.0)
|
43
|
+
rspec (3.6.0)
|
44
|
+
rspec-core (~> 3.6.0)
|
45
|
+
rspec-expectations (~> 3.6.0)
|
46
|
+
rspec-mocks (~> 3.6.0)
|
47
|
+
rspec-core (3.6.0)
|
48
|
+
rspec-support (~> 3.6.0)
|
49
|
+
rspec-expectations (3.6.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.6.0)
|
52
|
+
rspec-mocks (3.6.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.6.0)
|
55
|
+
rspec-support (3.6.0)
|
56
|
+
safe_yaml (1.0.4)
|
57
|
+
simplecov (0.15.0)
|
58
|
+
docile (~> 1.1.0)
|
59
|
+
json (>= 1.8, < 3)
|
60
|
+
simplecov-html (~> 0.10.0)
|
61
|
+
simplecov-html (0.10.2)
|
62
|
+
webmock (3.0.1)
|
63
|
+
addressable (>= 2.3.6)
|
64
|
+
crack (>= 0.3.2)
|
65
|
+
hashdiff
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
ruby
|
69
|
+
|
70
|
+
DEPENDENCIES
|
71
|
+
bundler (~> 1.0)
|
72
|
+
omniauth-zaif!
|
73
|
+
rack-test
|
74
|
+
rake
|
75
|
+
rspec (~> 3.2)
|
76
|
+
simplecov
|
77
|
+
webmock
|
78
|
+
|
79
|
+
BUNDLED WITH
|
80
|
+
1.15.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Norimitsu Yamashita
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# OmniAuth Zaif
|
2
|
+
|
3
|
+
This gem contains the Zaif OAuth2 Strategy for OmniAuth.
|
4
|
+
|
5
|
+
Supports the OAuth 2.0 Web Login. Read the Zaif developers docs for more details: https://corp.zaif.jp/api-docs/oauth/
|
6
|
+
|
7
|
+
## Using This Strategy
|
8
|
+
|
9
|
+
First start by adding this gem to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-zaif'
|
13
|
+
```
|
14
|
+
|
15
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
19
|
+
provider :zaif, "Client_ID", "Client_Secret"
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
## Authentication Hash
|
24
|
+
|
25
|
+
An example auth hash available in `request.env['omniauth.auth']`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
{
|
29
|
+
"provider" => "zaif",
|
30
|
+
"uid" => "a123b4....",
|
31
|
+
"info" => {
|
32
|
+
"email" => "taro.yamada@example.com",
|
33
|
+
"name" => "山田太郎",
|
34
|
+
"kana" => "ヤマダタロウ",
|
35
|
+
"certified" => true
|
36
|
+
},
|
37
|
+
"credentials" => {
|
38
|
+
"token" => "a123b4...", # The OAuth 2.0 access token
|
39
|
+
"refresh_token" => "a123b4...",
|
40
|
+
"expires_at" => 1504994039,
|
41
|
+
"expires" => true
|
42
|
+
},
|
43
|
+
"extra" => {}
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
## Licence
|
48
|
+
|
49
|
+
[MIT](https://github.com/nori3tsu/omniauth-zaif/blob/master/LICENSE)
|
50
|
+
|
51
|
+
## Author
|
52
|
+
|
53
|
+
[nori3tsu](https://github.com/nori3tsu)
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'omniauth-oauth2'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
class Zaif < OmniAuth::Strategies::OAuth2
|
9
|
+
option :name, 'zaif'
|
10
|
+
|
11
|
+
option :client_options, {
|
12
|
+
site: 'https://zaif.jp',
|
13
|
+
authorize_url: 'https://zaif.jp/oauth',
|
14
|
+
token_url: 'https://oauth.zaif.jp/v1/token'
|
15
|
+
}
|
16
|
+
|
17
|
+
def authorize_params
|
18
|
+
super.tap do |params|
|
19
|
+
params[:scope] ||= 'id_info'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
uid { raw_info['id'] }
|
24
|
+
|
25
|
+
info do
|
26
|
+
{
|
27
|
+
email: raw_info['email'],
|
28
|
+
name: raw_info['name'],
|
29
|
+
kana: raw_info['kana'],
|
30
|
+
certified: raw_info['certified']
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def raw_info
|
35
|
+
return @raw_info if @raw_info
|
36
|
+
|
37
|
+
uri = URI.parse('https://api.zaif.jp/tapi')
|
38
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
39
|
+
|
40
|
+
https.use_ssl = true
|
41
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
42
|
+
|
43
|
+
req['token'] = access_token.token
|
44
|
+
req.set_form_data({nonce: Time.now.to_i, method: 'get_id_info'})
|
45
|
+
res = https.request(req)
|
46
|
+
|
47
|
+
raise "failed to execute get_id_info. http status code: #{res.code}" unless res.code.to_i == 200
|
48
|
+
|
49
|
+
@raw_info = JSON.load(res.body)['return']['user']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-zaif/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-zaif"
|
7
|
+
s.version = OmniAuth::Zaif::VERSION
|
8
|
+
s.authors = ["nori3tsu"]
|
9
|
+
s.email = ["tugend.licht@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/nori3tsu/omniauth-zaif"
|
11
|
+
s.description = %q{OmniAuth strategy for Zaif}
|
12
|
+
s.summary = s.description
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'json', '~> 1.3'
|
21
|
+
s.add_dependency 'omniauth-oauth2', '~>1.3.1'
|
22
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Zaif do
|
4
|
+
let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
|
5
|
+
|
6
|
+
subject do
|
7
|
+
args = ['channel_id', 'secret', @options || {}].compact
|
8
|
+
OmniAuth::Strategies::Zaif.new(*args).tap do |strategy|
|
9
|
+
allow(strategy).to receive(:request) {
|
10
|
+
request
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'client options' do
|
16
|
+
it 'should have correct name' do
|
17
|
+
expect(subject.options.name).to eq('zaif')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have correct site' do
|
21
|
+
expect(subject.options.client_options.site).to eq('https://zaif.jp')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have correct authorize url' do
|
25
|
+
expect(subject.options.client_options.authorize_url).to eq('/oauth')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have correct token url' do
|
29
|
+
expect(subject.options.client_options.token_url).to eq('/v1/token')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'uid' do
|
34
|
+
before do
|
35
|
+
allow(subject).to receive(:raw_info).and_return(raw_info_hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should returns the uid' do
|
39
|
+
expect(subject.uid).to eq(raw_info_hash['mid'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'info' do
|
44
|
+
before do
|
45
|
+
allow(subject).to receive(:raw_info).and_return(raw_info_hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should returns the name' do
|
49
|
+
expect(subject.info[:name]).to eq(raw_info_hash['name'])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'request_phase' do
|
54
|
+
context 'with no request params set' do
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:request).and_return(
|
57
|
+
double('Request', {:params => {}})
|
58
|
+
)
|
59
|
+
allow(subject).to receive(:request_phase).and_return(:whatever)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not break' do
|
63
|
+
expect { subject.request_phase }.not_to raise_error
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def raw_info_hash
|
73
|
+
{
|
74
|
+
'uid' => 'hoge',
|
75
|
+
'name' => 'Foo Bar'
|
76
|
+
}
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
minimum_coverage(75.00)
|
6
|
+
end
|
7
|
+
require 'rspec'
|
8
|
+
require 'rack/test'
|
9
|
+
require 'webmock/rspec'
|
10
|
+
require 'omniauth'
|
11
|
+
require 'omniauth-zaif'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include WebMock::API
|
15
|
+
config.include Rack::Test::Methods
|
16
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
17
|
+
config.expect_with :rspec do |c|
|
18
|
+
c.syntax = :expect
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-zaif
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nori3tsu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: OmniAuth strategy for Zaif
|
56
|
+
email:
|
57
|
+
- tugend.licht@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/omniauth-zaif.rb
|
68
|
+
- lib/omniauth-zaif/version.rb
|
69
|
+
- lib/omniauth/strategies/zaif.rb
|
70
|
+
- omniauth-zaif.gemspec
|
71
|
+
- spec/omniauth/strategies/zaif_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: https://github.com/nori3tsu/omniauth-zaif
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: OmniAuth strategy for Zaif
|
97
|
+
test_files:
|
98
|
+
- spec/omniauth/strategies/zaif_spec.rb
|
99
|
+
- spec/spec_helper.rb
|