omniauth-weibo-oauth2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ *.swp
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # OmniAuth Weibo OAuth2
2
+
3
+ Weibo OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Read Weibo OAuth2 docs for more details: http://open.weibo.com/wiki/Oauth2
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-weibo-oauth2'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-weibo-oauth2
20
+
21
+ ## Usage
22
+
23
+ `OmniAuth::Strategies::Weibo` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
24
+
25
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
26
+
27
+ ```ruby
28
+ Rails.application.config.middleware.use OmniAuth::Builder do
29
+ provider :weibo, ENV['WEIBO_KEY'], ENV['WEIBO_SECRET']
30
+ end
31
+ ```
32
+
33
+ ## Authentication Hash
34
+
35
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
36
+
37
+ ```ruby
38
+ {
39
+ :provider => 'weibo',
40
+ :uid => '1234567890',
41
+ :info => {
42
+ :nickname => 'beenhero',
43
+ :name => 'beenhero',
44
+ :location => '浙江 杭州',
45
+ :image => 'http://tp4.sinaimg.cn/1640099215/50/1287016234/1',
46
+ :description => '移步twitter@beenhero',
47
+ :urls => { :Blog => 'http://beenhero.com'
48
+ :Weibo => 'http://weibo.com/beenhero'
49
+ },
50
+ },
51
+ :credentials => {
52
+ :token => '2.00JjgzmBd7F...', # OAuth 2.0 access_token, which you may wish to store
53
+ :expires_at => 1331780640, # when the access token expires (if it expires)
54
+ :expires => true # if you request `offline_access` this will be false
55
+ },
56
+ :extra => {
57
+ :raw_info => {
58
+ ... # data from /2/users/show.json, check by yourself
59
+ }
60
+ }
61
+ }
62
+ ```
63
+ *PS.* Built and tested on MRI Ruby 1.9.3
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
72
+
73
+ ## License
74
+
75
+ Copyright (c) 2012 by Bin He
76
+
77
+ 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:
78
+
79
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
80
+
81
+ 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,2 @@
1
+ require "omniauth-weibo-oauth2/version"
2
+ require 'omniauth/strategies/weibo'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module WeiboOauth2
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Weibo < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => "https://api.weibo.com",
8
+ :authorize_url => "/oauth2/authorize",
9
+ :token_url => "/oauth2/access_token"
10
+ }
11
+ option :token_params, {
12
+ :parse => :json
13
+ }
14
+
15
+ uid do
16
+ raw_info['id']
17
+ end
18
+
19
+ info do
20
+ {
21
+ :nickname => raw_info['screen_name'],
22
+ :name => raw_info['name'],
23
+ :location => raw_info['location'],
24
+ :image => raw_info['profile_image_url'],
25
+ :description => raw_info['description'],
26
+ :urls => {
27
+ 'Blog' => raw_info['url'],
28
+ 'Weibo' => raw_info['domain'].present?? "http://weibo.com/#{raw_info['domain']}" : "http://weibo.com/u/#{raw_info['id']}",
29
+ }
30
+ }
31
+ end
32
+
33
+ extra do
34
+ {
35
+ :raw_info => raw_info
36
+ }
37
+ end
38
+
39
+ def raw_info
40
+ access_token.options[:mode] = :query
41
+ access_token.options[:param_name] = 'access_token'
42
+ @uid ||= access_token.get('/2/account/get_uid.json').parsed["uid"]
43
+ @raw_info ||= access_token.get("/2/users/show.json", :params => {:uid => @uid}).parsed
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ OmniAuth.config.add_camelization "weibo", "Weibo"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-weibo-oauth2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "Bin He"
6
+ gem.email = "beenhero@gmail.com"
7
+ gem.description = %q{OmniAuth Oauth2 strategy for weibo.com.}
8
+ gem.summary = %q{OmniAuth Oauth2 strategy for weibo.com.}
9
+ gem.homepage = "https://github.com/beenhero/omniauth-weibo-oauth2"
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-weibo-oauth2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::WeiboOauth2::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-weibo-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bin He
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &70122148914480 !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: *70122148914480
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-oauth2
27
+ requirement: &70122148913920 !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: *70122148913920
36
+ description: OmniAuth Oauth2 strategy for weibo.com.
37
+ email: beenhero@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - .gitignore
43
+ - Gemfile
44
+ - README.md
45
+ - lib/omniauth-weibo-oauth2.rb
46
+ - lib/omniauth-weibo-oauth2/version.rb
47
+ - lib/omniauth/strategies/weibo.rb
48
+ - omniauth-weibo-oauth2.gemspec
49
+ homepage: https://github.com/beenhero/omniauth-weibo-oauth2
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.17
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: OmniAuth Oauth2 strategy for weibo.com.
73
+ test_files: []