omniauth-yahoojp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-yahoojp.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-yahoojp.gemspec')
10
+ end
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # OmniAuth YahooJp
2
+
3
+ This is the official OmniAuth strategy for authenticating to Yahoo! JAPAN( [YConnect](http://developer.yahoo.co.jp/yconnect/) ).
4
+ To use it, you'll need to sign up for a YConnect Application ID and Secret
5
+ on the [Yahoo! JAPAN Developer Network](https://e.developer.yahoo.co.jp/dashboard/).
6
+
7
+ ## Basic Usage
8
+
9
+ use OmniAuth::Builder do
10
+ provider :yahoojp, ENV['YAHOOJP_KEY'], ENV['YAHOOJP_SECRET']
11
+ end
12
+
13
+ ## Scopes
14
+
15
+ YConnect API v1 lets you set scopes to provide granular access to different types of data:
16
+
17
+ use OmniAuth::Builder do
18
+ provider :yahoojp, ENV['YAHOOJP_KEY'], ENV['YAHOOJP_SECRET'], scope: "openid,profile,email,address"
19
+ end
20
+
21
+ More info on [YConnect](http://developer.yahoo.co.jp/yconnect/).
22
+
23
+ ## License
24
+
25
+ Copyright (c) 2013 by mikanmarusan
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-yahoojp/version"
2
+ require 'omniauth/strategies/yahoojp'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module YahooJp
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class YahooJp < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, 'yahoojp'
8
+ option :client_options, {
9
+ :site => 'https://auth.login.yahoo.co.jp',
10
+ :authorize_url => '/yconnect/v1/authorization',
11
+ :token_url => '/yconnect/v1/token'
12
+ }
13
+
14
+ option :authorize_options, [:display, :prompt, :scope]
15
+
16
+ def request_phase
17
+ super
18
+ end
19
+
20
+ uid { raw_info['user_id'] }
21
+
22
+ info do
23
+ prune!({
24
+ :name => raw_info['name'],
25
+ :email => raw_info['email'],
26
+ :first_name => raw_info['given_name'],
27
+ :last_name => raw_info['family_name'],
28
+ :urls => {
29
+ 'YahooJp' => raw_info['link'],
30
+ },
31
+ })
32
+ end
33
+
34
+ extra do
35
+ hash = {}
36
+ hash[:raw_info] = raw_info unless skip_info?
37
+ prune! hash
38
+ end
39
+
40
+ def raw_info
41
+ access_token.options[:mode] = :header
42
+ @raw_info ||= access_token.get('https://userinfo.yahooapis.jp/yconnect/v1/attribute?schema=openid').parsed
43
+ end
44
+
45
+ def prune!(hash)
46
+ hash.delete_if do |_, value|
47
+ prune!(value) if value.is_a?(Hash)
48
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
49
+ end
50
+ end
51
+
52
+ def build_access_token
53
+ token_params = {
54
+ :code => request.params['code'],
55
+ :redirect_uri => callback_url,
56
+ :grant_type => 'authorization_code',
57
+ :headers => {'Authorization' => HTTPAuth::Basic.pack_authorization(client.id, client.secret)}
58
+ }
59
+
60
+ client.get_token(token_params);
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+
67
+ OmniAuth.config.add_camelization 'yahoojp', 'YahooJp'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-yahoojp/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["mikanmarusan"]
6
+ gem.email = ["chiakifujimon@gmail.com"]
7
+ gem.description = %q{Official OmniAuth strategy for Yahoo! JAPAN.}
8
+ gem.summary = %q{Official OmniAuth strategy for Yahoo! JAPAN.}
9
+ gem.homepage = "https://github.com/mikanmarusan/omniauth-yahoojp"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-yahoojp"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::YahooJp::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.1'
20
+ gem.add_development_dependency 'rspec', '~> 2.7'
21
+ gem.add_development_dependency 'rack-test'
22
+ gem.add_development_dependency 'simplecov'
23
+ gem.add_development_dependency 'webmock'
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-yahoojp'
3
+
4
+ describe OmniAuth::Strategies::YahooJp do
5
+
6
+ subject do
7
+ OmniAuth::Strategies::YahooJp.new({})
8
+ end
9
+
10
+ context "client options" do
11
+ it 'should have correct site' do
12
+ subject.options.client_options.site.should eq("https://auth.login.yahoo.co.jp")
13
+ end
14
+
15
+ it 'should have correct authorize url' do
16
+ subject.options.client_options.authorize_url.should eq('/yconnect/v1/authorization')
17
+ end
18
+
19
+ it 'should have correct token url' do
20
+ subject.options.client_options.token_url.should eq('/yconnect/v1/token')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-yahoojp'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-yahoojp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - mikanmarusan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-03-04 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ version: "1.0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: omniauth-oauth2
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 1
43
+ version: "1.1"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 7
56
+ version: "2.7"
57
+ type: :development
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rack-test
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id004
71
+ - !ruby/object:Gem::Dependency
72
+ name: simplecov
73
+ prerelease: false
74
+ requirement: &id005 !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ type: :development
82
+ version_requirements: *id005
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ prerelease: false
86
+ requirement: &id006 !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id006
95
+ description: Official OmniAuth strategy for Yahoo! JAPAN.
96
+ email:
97
+ - chiakifujimon@gmail.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - Gemfile
108
+ - Guardfile
109
+ - README.md
110
+ - Rakefile
111
+ - lib/omniauth-yahoojp.rb
112
+ - lib/omniauth-yahoojp/version.rb
113
+ - lib/omniauth/strategies/yahoojp.rb
114
+ - omniauth-yahoojp.gemspec
115
+ - spec/omniauth/strategies/yahoojp_spec.rb
116
+ - spec/spec_helper.rb
117
+ has_rdoc: true
118
+ homepage: https://github.com/mikanmarusan/omniauth-yahoojp
119
+ licenses: []
120
+
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.3.6
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Official OmniAuth strategy for Yahoo! JAPAN.
147
+ test_files:
148
+ - spec/omniauth/strategies/yahoojp_spec.rb
149
+ - spec/spec_helper.rb