omniauth-tqq 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-tqq.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "omniauth-tqq/version"
2
+ require 'omniauth/strategies/tqq'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Tqq
3
+ VERSION = "1.0.0.rc2"
4
+ end
5
+ end
@@ -0,0 +1,78 @@
1
+ require 'omniauth-oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Tqq < OmniAuth::Strategies::OAuth
7
+ option :name, 'tqq'
8
+ option :sign_in, true
9
+ def initialize(*args)
10
+ super
11
+ # taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tqq.rb#L15-24
12
+ options.client_options = {
13
+ :access_token_path => '/cgi-bin/access_token',
14
+ :authorize_path => '/cgi-bin/authorize',
15
+ :http_method => :get,
16
+ :nonce => nonce,
17
+ :realm => 'OmniAuth',
18
+ :request_token_path => '/cgi-bin/request_token',
19
+ :scheme => :query_string,
20
+ :site => 'https://open.t.qq.com',
21
+ }
22
+ end
23
+
24
+ # https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tqq.rb#L28-30
25
+ def nonce
26
+ Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
27
+ end
28
+
29
+ def consumer
30
+ consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
31
+ consumer
32
+ end
33
+
34
+ uid { access_token.params[:id] }
35
+
36
+ info do
37
+ {
38
+ :nickname => raw_info['data']['nick'],
39
+ :name => raw_info['data']['name'],
40
+ :location => raw_info['data']['location'],
41
+ :image => raw_info['data']['head'],
42
+ :description => raw_info['description'],
43
+ :urls => {
44
+ 'Tqq' => 't.qq.com'
45
+ }
46
+ }
47
+ end
48
+
49
+ extra do
50
+ { :raw_info => raw_info }
51
+ end
52
+
53
+ #taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tsina.rb#L52-67
54
+ def request_phase
55
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
56
+ session['oauth'] ||= {}
57
+ session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
58
+
59
+ if request_token.callback_confirmed?
60
+ redirect request_token.authorize_url(options[:authorize_params])
61
+ else
62
+ redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
63
+ end
64
+
65
+ rescue ::Timeout::Error => e
66
+ fail!(:timeout, e)
67
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
68
+ fail!(:service_unavailable, e)
69
+ end
70
+
71
+ def raw_info
72
+ @raw_info ||= MultiJson.decode(access_token.get('http://open.t.qq.com/api/user/info?format=json').body)
73
+ rescue ::Errno::ETIMEDOUT
74
+ raise ::Timeout::Error
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-tqq/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-tqq"
7
+ s.version = Omniauth::Tqq::VERSION
8
+ s.authors = ["Scott Ballantyne"]
9
+ s.email = ["ussballantyne@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{an omniauth strategy for tencent weibo}
12
+ s.description = %q{an omniauth strategy for tencent weibo}
13
+
14
+ s.rubyforge_project = "omniauth-tqq"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tqq
3
+ version: !ruby/object:Gem::Version
4
+ hash: 724092137
5
+ prerelease: 6
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - rc
11
+ - 2
12
+ version: 1.0.0.rc2
13
+ platform: ruby
14
+ authors:
15
+ - Scott Ballantyne
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-10-29 00:00:00 Z
21
+ dependencies: []
22
+
23
+ description: an omniauth strategy for tencent weibo
24
+ email:
25
+ - ussballantyne@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - README
36
+ - Rakefile
37
+ - lib/omniauth-tqq.rb
38
+ - lib/omniauth-tqq/version.rb
39
+ - lib/omniauth/strategies/tqq.rb
40
+ - omniauth-tqq.gemspec
41
+ homepage: ""
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">"
62
+ - !ruby/object:Gem::Version
63
+ hash: 25
64
+ segments:
65
+ - 1
66
+ - 3
67
+ - 1
68
+ version: 1.3.1
69
+ requirements: []
70
+
71
+ rubyforge_project: omniauth-tqq
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: an omniauth strategy for tencent weibo
76
+ test_files: []
77
+