omniauth-google-oauth2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :example do
6
+ gem 'sinatra'
7
+ end
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # OmniAuth Google Oauth2 Strategy
2
+
3
+ Strategy to auth with Google via Oauth2 in OmniAuth.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup :default, :development, :example
5
+ require 'sinatra'
6
+ require 'omniauth'
7
+ require 'omniauth-google-oauth2'
8
+
9
+ use Rack::Session::Cookie
10
+
11
+ use OmniAuth::Builder do
12
+ provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
13
+ end
14
+
15
+ get '/' do
16
+ <<-HTML
17
+ <ul>
18
+ <li><a href='/auth/google_oauth2'>Sign in with Google</a></li>
19
+ </ul>
20
+ HTML
21
+ end
22
+
23
+ get '/auth/:provider/callback' do
24
+ content_type 'text/plain'
25
+ request.env['omniauth.auth'].info.to_hash.inspect
26
+ end
@@ -0,0 +1,8 @@
1
+ require "omniauth-google-oauth2/version"
2
+ require "omniauth"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ autoload :GoogleOauth2, 'omniauth/strategies/google_oauth2'
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module GoogleOauth2
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class GoogleOauth2 < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => 'https://accounts.google.com',
8
+ :authorize_url => '/o/oauth2/auth',
9
+ :token_url => '/o/oauth2/token'
10
+ }
11
+
12
+ def request_phase
13
+ google_email_scope = "www.googleapis.com/auth/userinfo.email"
14
+ options[:scope] ||= "https://#{google_email_scope}"
15
+ options[:scope] << " https://#{google_email_scope}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
16
+ redirect client.auth_code.authorize_url(
17
+ {:redirect_uri => callback_url, :response_type => "code"}.merge(options))
18
+ end
19
+
20
+ def auth_hash
21
+ OmniAuth::Utils.deep_merge(super, {
22
+ 'uid' => info['uid'],
23
+ 'info' => info,
24
+ 'credentials' => {'expires_at' => @access_token.expires_at},
25
+ 'extra' => {'user_hash' => user_data}
26
+ })
27
+ end
28
+
29
+ info do
30
+ {
31
+ 'email' => "TESTING EMAIL",
32
+ 'uid' => "TESTING UID",
33
+ 'name' => "TESTING NAME"
34
+ }
35
+ end
36
+
37
+ def user_data
38
+ @data ||=
39
+ @access_token.get("https://www.googleapis.com/userinfo/email?alt=json").parsed
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
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"]
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
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-google-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Josh Ellithorpe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-03 00:00:00 -07:00
19
+ default_executable:
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
+ description: A Google oauth2 strategy for OmniAuth 1.0
37
+ email:
38
+ - quest@mac.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - examples/sinatra.rb
51
+ - lib/omniauth-google-oauth2.rb
52
+ - lib/omniauth-google-oauth2/version.rb
53
+ - lib/omniauth/strategies/google_oauth2.rb
54
+ - omniauth-contrib.gemspec
55
+ has_rdoc: true
56
+ homepage: ""
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.6.2
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A Google oauth2 strategy for OmniAuth 1.0
89
+ test_files: []
90
+