omniauth-tqq-oauth2 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-tqq-oauth2.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 cqpx
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Omniauth::Tqq::Oauth2
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omniauth-tqq-oauth2'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omniauth-tqq-oauth2
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,88 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Tqq < OmniAuth::Strategies::OAuth2
6
+ # Give your strategy a name.
7
+ option :name, "tqq"
8
+
9
+ # This is where you pass the options you would pass when
10
+ # initializing your consumer from the OAuth gem.
11
+ option :client_options, {
12
+ :site => "https://open.t.qq.com",
13
+ :authorize_url => "/cgi-bin/oauth2/authorize",
14
+ :token_url => "/cgi-bin/oauth2/access_token"
15
+ }
16
+ option :token_params, {
17
+ :parse => :query
18
+ }
19
+
20
+ # These are called after authentication has succeeded. If
21
+ # possible, you should try to set the UID without making
22
+ # additional calls (if the user id is returned with the token
23
+ # or as a URI parameter). This may not be possible with all
24
+ # providers.
25
+ uid {
26
+ access_token["openid"]
27
+ }
28
+
29
+ info do
30
+ {
31
+ :name => raw_info['name'],
32
+ :email => raw_info['email']
33
+ }
34
+ end
35
+
36
+ extra do
37
+ {
38
+ 'raw_info' => raw_info
39
+ }
40
+ end
41
+
42
+ credentials do
43
+ hash = {'token' => access_token.token}
44
+ hash.merge!('openid' => @openid) if @openid
45
+ hash.merge!('openkey' => @openkey) if @openkey
46
+ hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
47
+ hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
48
+ hash.merge!('expires' => access_token.expires?)
49
+ hash
50
+ end
51
+
52
+ def build_access_token
53
+ verifier = request.params['code']
54
+ @ac_token ||= client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)))
55
+ end
56
+
57
+ def callback_phase
58
+ if request.params['error'] || request.params['error_reason']
59
+ raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
60
+ end
61
+
62
+ self.access_token = build_access_token
63
+ self.access_token = access_token.refresh! if access_token.expired?
64
+ @openid = request.params["openid"]
65
+ @openkey = request.params["openkey"]
66
+
67
+ super
68
+ rescue ::OAuth2::Error, CallbackError => e
69
+ fail!(:invalid_credentials, e)
70
+ rescue ::MultiJson::DecodeError => e
71
+ fail!(:invalid_response, e)
72
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
73
+ fail!(:timeout, e)
74
+ rescue ::SocketError => e
75
+ fail!(:failed_to_connect, e)
76
+ end
77
+
78
+ def raw_info
79
+ @raw_info ||= access_token.get("/api/user/info", params: {
80
+ openid: @openid,
81
+ oauth_consumer_key: access_token.client.id,
82
+ access_token: access_token.token,
83
+ oauth_version: '2.a'
84
+ }, parse: :json).parsed
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,7 @@
1
+ module Omniauth
2
+ module Tqq
3
+ module Oauth2
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-tqq-oauth2/version"
2
+ require 'omniauth/strategies/tqq'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-tqq-oauth2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["cqpx"]
6
+ gem.email = ["cqpanxu@gmail.com"]
7
+ gem.description = %q{OmniAuth Oauth2 strategy for t.qq.com.}
8
+ gem.summary = %q{OmniAuth Oauth2 strategy for t.qq.com.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "omniauth-tqq-oauth2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Omniauth::Tqq::Oauth2::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tqq-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cqpx
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &70093352639220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70093352639220
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-oauth2
27
+ requirement: &70093352638500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70093352638500
36
+ description: OmniAuth Oauth2 strategy for t.qq.com.
37
+ email:
38
+ - cqpanxu@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/omniauth-tqq-oauth2.rb
49
+ - lib/omniauth-tqq-oauth2/version.rb
50
+ - lib/omniauth/strategies/tqq.rb
51
+ - omniauth-tqq-oauth2.gemspec
52
+ homepage: ''
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.16
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: OmniAuth Oauth2 strategy for t.qq.com.
76
+ test_files: []