omniauth-qq-connect 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/lib/omniauth-qq-connect.rb +2 -0
- data/lib/omniauth-qq-connect/version.rb +7 -0
- data/lib/omniauth/strategies/qq_connect.rb +55 -0
- data/omniauth-qq-connect.gemspec +20 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kai Chen
|
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,35 @@
|
|
1
|
+
# Omniauth::Qq::Connect
|
2
|
+
|
3
|
+
This is the OmniAuth strategy for authenticating to QQ connect. To
|
4
|
+
use it, you'll need to sign up for an OAuth2 Application Key and Secret
|
5
|
+
on the [QQ Open SNS Page](http://connect.qq.com/intro/login/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'omniauth-qq-connect'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-qq-connect
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
use OmniAuth::Builder do
|
24
|
+
provider :qq_connect, ENV['QQ_CONNECT_APP_KEY'], ENV['QQ_CONNECT_APP_SECRET']
|
25
|
+
end
|
26
|
+
|
27
|
+
*Notice* you only allow send the auth request from host(w/o port) list of application.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'omniauth/strategies/oauth2'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class QQConnect < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, "qq_connect"
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
:site => 'https://graph.qq.com/oauth2.0/',
|
12
|
+
:authorize_url => '/oauth2.0/authorize',
|
13
|
+
:token_url => "/oauth2.0/token"
|
14
|
+
}
|
15
|
+
|
16
|
+
option :token_params, {
|
17
|
+
:state => 'foobar',
|
18
|
+
:parse => :query
|
19
|
+
}
|
20
|
+
|
21
|
+
uid do
|
22
|
+
raw_info
|
23
|
+
end
|
24
|
+
|
25
|
+
info { user_info }
|
26
|
+
|
27
|
+
def raw_info
|
28
|
+
@raw_info ||= begin
|
29
|
+
access_token.options[:mode] = :query
|
30
|
+
access_token.options[:param_name] = :access_token
|
31
|
+
# Response Example: "callback( {\"client_id\":\"11111\",\"openid\":\"000000FFFF\"} );\n"
|
32
|
+
response = access_token.get('/oauth2.0/me')
|
33
|
+
#TODO handle error case
|
34
|
+
matched = response.body.match(/"openid":"(?<openid>\w+)"/)
|
35
|
+
matched[:openid]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_info
|
40
|
+
@user_info ||= begin
|
41
|
+
#TODO handle error case
|
42
|
+
#TODO make info request url configurable
|
43
|
+
client.request(:get, "https://graph.qq.com/user/get_user_info", :params => {
|
44
|
+
:format => :json,
|
45
|
+
:openid => uid,
|
46
|
+
:oauth_consumer_key => options[:client_id],
|
47
|
+
:access_token => access_token.token
|
48
|
+
}, :parse => :json).parsed
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
OmniAuth.config.add_camelization('qq_connect', 'QQConnect')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-qq-connect/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kai Chen"]
|
6
|
+
gem.email = ["kaichenxyz@gmail.com"]
|
7
|
+
gem.description = %q{OmniAuth strategy for QQ Connect.}
|
8
|
+
gem.summary = %q{OmniAuth strategy for QQ Connect.}
|
9
|
+
gem.homepage = ""
|
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-qq-connect"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Omniauth::Qq::Connect::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-qq-connect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kai Chen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: &70144482823240 !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: *70144482823240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: omniauth-oauth2
|
27
|
+
requirement: &70144482822740 !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: *70144482822740
|
36
|
+
description: OmniAuth strategy for QQ Connect.
|
37
|
+
email:
|
38
|
+
- kaichenxyz@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-qq-connect.rb
|
49
|
+
- lib/omniauth-qq-connect/version.rb
|
50
|
+
- lib/omniauth/strategies/qq_connect.rb
|
51
|
+
- omniauth-qq-connect.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 strategy for QQ Connect.
|
76
|
+
test_files: []
|