omniauth-baidu-social 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83ffa53ceade466d27018815c052422a25fbb6cf
4
+ data.tar.gz: 0d2e64c698f441acbbb5f24fcbc76629f3f021c0
5
+ SHA512:
6
+ metadata.gz: c620137aaeb1aa087638f1adec0a5df3a42fcdd690627ac6212a41a3955b2663d0401854e1764101ddb43e578a3f664ed2df77d780713a0104b50f0accecdb8b
7
+ data.tar.gz: ca6823302c40b3981980853918654e97d54c1c746716f113d0c5f38c86913d8f2de359a5b7ee9d6203fdbc2bde8c8f4597dc2f0371e111963ce9a7ec5a395ee4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'http://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
13
+
14
+ group :test do
15
+ gem "rack-test", require: "rack/test"
16
+ gem 'simplecov'
17
+ gem 'webmock'
18
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-baidu-social.gemspec')
10
+ end
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # OmniAuth Baidu OAuth2
2
+
3
+ Baidu OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Read Baidu OAuth2 docs for more details: http://developer.baidu.com/wiki/index.php?title=docs/social
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-baidu-social'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-baidu-social
20
+
21
+ ## Usage
22
+
23
+ `OmniAuth::Strategies::Baidu` 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 :baidu, ENV['BAIDU_SOCIAL_KEY'], ENV['BAIDU_SOCIAL_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 => 'baidu',
40
+ :uid => '1234567890',
41
+ :info => {
42
+ :social_uid => '1234567890',
43
+ :name => 'destinyd',
44
+ :media_uid => '0987654321',
45
+ :media_type => 'sinaweibo',
46
+ :is_verified => raw_info['is_verified']
47
+ },
48
+ :credentials => {
49
+ :token => '2.00JjgzmBd7F...', # OAuth 2.0 access_token, which you may wish to store
50
+ :expires_at => 1331780640, # when the access token expires (if it expires)
51
+ :expires => true # if you request `offline_access` this will be false
52
+ },
53
+ :extra => {
54
+ :raw_info => {
55
+ ... # data from /social/api/2.0/user/info.json, check by yourself
56
+ }
57
+ }
58
+ }
59
+ ```
60
+ *PS.* Built and tested on MRI Ruby 1.9.3
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
69
+
70
+ ## License
71
+
72
+ Copyright (c) 2012 by Bin He
73
+
74
+ 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:
75
+
76
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77
+
78
+ 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.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-baidu-social/version"
2
+ require 'omniauth/strategies/baidu'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BaiduSocial
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require "omniauth-oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Baidu < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ :site => "https://openapi.baidu.com",
8
+ :authorize_url => "/social/oauth/2.0/authorize",
9
+ :token_url => "/social/oauth/2.0/token"
10
+ }
11
+
12
+ option :token_params, {
13
+ :parse => :json,
14
+ }
15
+
16
+ #option :auth_token_params, {
17
+ #}
18
+
19
+ option :provider_ignores_state, true
20
+
21
+ uid do
22
+ raw_info['social_uid']
23
+ end
24
+
25
+ info do
26
+ {
27
+ :social_uid => raw_info['social_uid'],
28
+ :name => raw_info['username'],
29
+ :media_type => raw_info['media_type'],
30
+ :media_uid => raw_info['media_uid'],
31
+ :is_verified => raw_info['is_verified'],
32
+
33
+ #:birthday => raw_info['birthday'],
34
+ #:tinyurl => raw_info['tinyurl'],
35
+ #:headurl => raw_info['headurl'],
36
+ #:mainurl => raw_info['mainurl'],
37
+ #:hometown_location => raw_info['hometown_location'],
38
+ #:work_history => raw_info['work_history'],
39
+ #:university_history => raw_info['university_history'],
40
+ #:hs_history => raw_info['hs_history'],
41
+ #:province => raw_info['province'],
42
+ #:city => raw_info['city'],
43
+ }
44
+ end
45
+
46
+ extra do
47
+ {
48
+ :raw_info => raw_info
49
+ }
50
+ end
51
+
52
+ def raw_info
53
+ access_token.options[:mode] = :query
54
+ #access_token.options[:param_name] = 'access_token'
55
+ @raw_info ||= access_token.get("/social/api/2.0/user/info").parsed
56
+ end
57
+
58
+ protected
59
+
60
+ end
61
+ end
62
+ end
63
+
64
+ OmniAuth.config.add_camelization "baidu", "Baidu"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-baidu-social/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "DestinyD"
6
+ gem.email = "destinyd.war@gmail.com"
7
+ gem.description = %q{OmniAuth Oauth2 strategy for baidu.com.}
8
+ gem.summary = %q{OmniAuth Oauth2 strategy for baidu.com.}
9
+ gem.homepage = "https://github.com/destinyd/omniauth-baidu-social"
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-baidu-social"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::BaiduSocial::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Baidu do
4
+ let(:access_token) { stub('AccessToken', :options => {}) }
5
+ let(:parsed_response) { stub('ParsedResponse') }
6
+ let(:response) { stub('Response', :parsed => parsed_response) }
7
+
8
+ let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
9
+ let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
10
+ let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
11
+ let(:enterprise) do
12
+ OmniAuth::Strategies::Baidu.new('GITHUB_KEY', 'GITHUB_SECRET',
13
+ {
14
+ :client_options => {
15
+ :site => enterprise_site,
16
+ :authorize_url => enterprise_authorize_url,
17
+ :token_url => enterprise_token_url
18
+ }
19
+ }
20
+ )
21
+ end
22
+
23
+ subject do
24
+ OmniAuth::Strategies::Baidu.new({})
25
+ end
26
+
27
+ before(:each) do
28
+ subject.stub!(:access_token).and_return(access_token)
29
+ end
30
+
31
+ context "client options" do
32
+ it 'should have correct site' do
33
+ subject.options.client_options.site.should eq("https://openapi.baidu.com")
34
+ end
35
+
36
+ it 'should have correct authorize url' do
37
+ subject.options.client_options.authorize_url.should eq('/social/oauth/2.0/authorize')
38
+ end
39
+
40
+ it 'should have correct token url' do
41
+ subject.options.client_options.token_url.should eq('/social/oauth/2.0/token')
42
+ end
43
+
44
+ describe "should be overrideable" do
45
+ it "for site" do
46
+ enterprise.options.client_options.site.should eq(enterprise_site)
47
+ end
48
+
49
+ it "for authorize url" do
50
+ enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url)
51
+ end
52
+
53
+ it "for token url" do
54
+ enterprise.options.client_options.token_url.should eq(enterprise_token_url)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "#raw_info" do
60
+ it "should use relative paths" do
61
+ access_token.should_receive(:get).with('/social/api/2.0/user/info').and_return(response)
62
+ subject.raw_info.should eq(parsed_response)
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-baidu-social'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-baidu-social
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - DestinyD
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: OmniAuth Oauth2 strategy for baidu.com.
42
+ email: destinyd.war@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Guardfile
50
+ - README.md
51
+ - Rakefile
52
+ - lib/omniauth-baidu-social.rb
53
+ - lib/omniauth-baidu-social/version.rb
54
+ - lib/omniauth/strategies/baidu.rb
55
+ - omniauth-baidu-social.gemspec
56
+ - spec/omniauth/strategies/baidu_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/destinyd/omniauth-baidu-social
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: OmniAuth Oauth2 strategy for baidu.com.
81
+ test_files:
82
+ - spec/omniauth/strategies/baidu_spec.rb
83
+ - spec/spec_helper.rb