omniauth-google_oauth2 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
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
18
+ .powenv
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ree@omniauth-google-oauth2 --create
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :example do
6
+ gem 'sinatra'
7
+ end
@@ -0,0 +1,13 @@
1
+ # OmniAuth Google OAuth2 Strategy
2
+
3
+ Strategy to auth with Google via OAuth2 in OmniAuth.
4
+
5
+ ## License
6
+
7
+ Copyright (c) 2011 by Josh Ellithorpe
8
+
9
+ 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:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ 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.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,41 @@
1
+ # Sample app for Google OAuth2 Strategy
2
+ # Make sure to setup the ENV variables GOOGLE_KEY and GOOGLE_SECRET
3
+ # Run with "bundle exec rackup"
4
+
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'sinatra'
8
+ require 'omniauth'
9
+ require 'omniauth-google-oauth2'
10
+
11
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
12
+
13
+ class App < Sinatra::Base
14
+ get '/' do
15
+ <<-HTML
16
+ <ul>
17
+ <li><a href='/auth/google_oauth2'>Sign in with Google</a></li>
18
+ </ul>
19
+ HTML
20
+ end
21
+
22
+ get '/auth/:provider/callback' do
23
+ content_type 'text/plain'
24
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
25
+ end
26
+
27
+ get '/auth/failure' do
28
+ content_type 'text/plain'
29
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
30
+ end
31
+ end
32
+
33
+ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
34
+
35
+ use OmniAuth::Builder do
36
+ provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], {
37
+ :scope => 'https://www.googleapis.com/auth/plus.me'
38
+ }
39
+ end
40
+
41
+ run App.new
@@ -0,0 +1 @@
1
+ require "omniauth/google_oauth2"
@@ -0,0 +1,2 @@
1
+ require 'omniauth/google_oauth2/version'
2
+ require 'omniauth/strategies/google_oauth2'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module GoogleOauth2
3
+ VERSION = "0.1.5"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class GoogleOAuth2 < OmniAuth::Strategies::OAuth2
6
+ option :name, 'google_oauth2'
7
+
8
+ option :client_options, {
9
+ :site => 'https://accounts.google.com',
10
+ :authorize_url => '/o/oauth2/auth',
11
+ :token_url => '/o/oauth2/token'
12
+ }
13
+
14
+ def request_phase
15
+ setup_authorize_params
16
+ super
17
+ end
18
+
19
+ def setup_authorize_params
20
+ opts = {
21
+ :client_id => options[:client_id],
22
+ :redirect_uri => callback_url,
23
+ :response_type => "code",
24
+ :scope => options[:scope]
25
+ }
26
+ google_email_scope = "www.googleapis.com/auth/userinfo.email"
27
+ opts[:scope] ||= "https://#{google_email_scope}"
28
+ opts[:scope] << " https://#{google_email_scope}" unless opts[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
29
+ options[:authorize_params] = opts.merge(options[:authorize_params])
30
+ end
31
+
32
+ def auth_hash
33
+ OmniAuth::Utils.deep_merge(super, {
34
+ 'uid' => info['uid'],
35
+ 'info' => info,
36
+ 'credentials' => {'expires_at' => access_token.expires_at},
37
+ 'extra' => {'user_hash' => user_data}
38
+ })
39
+ end
40
+
41
+ info do
42
+ if user_data['data']['isVerified']
43
+ email = user_data['data']['email'] rescue nil
44
+ else
45
+ email = nil
46
+ end
47
+
48
+ {
49
+ 'email' => email,
50
+ 'uid' => email,
51
+ 'name' => email
52
+ }
53
+ end
54
+
55
+ def user_data
56
+ @data ||= access_token.get("https://www.googleapis.com/userinfo/email?alt=json").parsed
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/google_oauth2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 1.0'
6
+
7
+ gem.authors = ["Josh Ellithorpe", "pepusz"]
8
+ gem.email = ["quest@mac.com"]
9
+ gem.description = %q{A Google oauth2 strategy for OmniAuth 1.0}
10
+ gem.summary = %q{A Google oauth2 strategy for OmniAuth 1.0}
11
+ gem.homepage = ""
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.name = "omniauth-google_oauth2"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = OmniAuth::GoogleOauth2::VERSION
19
+
20
+ gem.add_runtime_dependency 'omniauth-oauth2'
21
+
22
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-google-oauth2'
3
+
4
+ describe OmniAuth::Strategies::GoogleOauth2 do
5
+ subject do
6
+ OmniAuth::Strategies::GoogleOauth2.new(nil, @options || {})
7
+ end
8
+
9
+ it_should_behave_like 'an oauth2 strategy'
10
+
11
+ describe '#client' do
12
+ it 'has correct Google site' do
13
+ subject.client.site.should eq('https://accounts.google.com')
14
+ end
15
+
16
+ it 'has correct authorize url' do
17
+ subject.client.options[:authorize_url].should eq('/o/oauth2/auth')
18
+ end
19
+
20
+ it 'has correct token url' do
21
+ subject.client.options[:token_url].should eq('/o/oauth2/token')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it "has the correct callback path" do
27
+ subject.callback_path.should eq('/auth/google_oauth2/callback')
28
+ end
29
+ end
30
+
31
+ # These are setup during the request_phase
32
+ # At init they are blank
33
+ describe '#authorize_params' do
34
+ it "has no authorize params at init" do
35
+ subject.authorize_params.should be_empty
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any token params passed in the :token_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :token_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-google_oauth2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 5
10
+ version: 0.1.5
11
+ platform: ruby
12
+ authors:
13
+ - Josh Ellithorpe
14
+ - pepusz
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-11-20 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: omniauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: omniauth-oauth2
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 2
61
+ - 6
62
+ - 0
63
+ version: 2.6.0
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rake
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :development
79
+ version_requirements: *id004
80
+ description: A Google oauth2 strategy for OmniAuth 1.0
81
+ email:
82
+ - quest@mac.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files: []
88
+
89
+ files:
90
+ - .gitignore
91
+ - .rvmrc
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - examples/config.ru
96
+ - lib/omniauth-google_oauth2.rb
97
+ - lib/omniauth/google_oauth2.rb
98
+ - lib/omniauth/google_oauth2/version.rb
99
+ - lib/omniauth/strategies/google_oauth2.rb
100
+ - omniauth-contrib.gemspec
101
+ - spec/omniauth/strategies/google_oauth2_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/shared_examples.rb
104
+ homepage: ""
105
+ licenses: []
106
+
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.10
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: A Google oauth2 strategy for OmniAuth 1.0
137
+ test_files:
138
+ - spec/omniauth/strategies/google_oauth2_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support/shared_examples.rb