omniauth-baidu-oauth2 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/README.md +43 -0
- data/lib/omniauth-baidu-oauth2.rb +2 -0
- data/lib/omniauth-baidu-oauth2/version.rb +6 -0
- data/lib/omniauth/strategies/baidu.rb +70 -0
- data/omniauth-baidu-oauth2.gemspec +20 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cc12774de7ce74adf9a3f8ba587e37bd733b8f9
|
4
|
+
data.tar.gz: ae9fb8ec6583ef87601489f68c168373a7a53ea6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9f0e4b36309f4e9d8a6c0a229c4d8bf6bca866c1b5935f6cda93d76ae34e23bb5b361919e774512301e5b8547fcd27323027a7e3455bbe8e5c0f54e195d5490
|
7
|
+
data.tar.gz: b11e65f96ea818d905c3cff26ea2c43944a42db024719db4ea99339e75f5feec9e4c7f3f5733604ab90118b9f74857c9648e34c1a98f72561c9cc772457a3b18
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Oauth2::Baidu
|
2
|
+
|
3
|
+
OmniAuth Oauth2 strategy for baidu.com
|
4
|
+
|
5
|
+
http://developer.baidu.com/wiki/index.php?title=docs/oauth
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'omniauth-baidu-oauth2'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-baidu-oauth2
|
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_KEY'], ENV['BAIDU_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
MIT
|
@@ -0,0 +1,70 @@
|
|
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 => "/oauth/2.0/authorize",
|
9
|
+
:token_url => "/oauth/2.0/token"
|
10
|
+
}
|
11
|
+
option :token_params, {
|
12
|
+
:parse => :json
|
13
|
+
}
|
14
|
+
|
15
|
+
uid do
|
16
|
+
raw_info['userid']
|
17
|
+
end
|
18
|
+
|
19
|
+
info do
|
20
|
+
{
|
21
|
+
:nickname => raw_info['realname'],
|
22
|
+
:name => raw_info['username'],
|
23
|
+
:sex => raw_info['sex'],
|
24
|
+
:birthday => raw_info['birthday'],
|
25
|
+
:description => raw_info['userdetail'],
|
26
|
+
:image => {
|
27
|
+
'small' => "http://tb.himg.baidu.com/sys/portraitn/item/#{raw_info['url']}",
|
28
|
+
'large' => "http://tb.himg.baidu.com/sys/portrait/item/#{raw_info['url']}",
|
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('/rest/2.0/passport/users/getLoggedInUser').parsed["uid"]
|
43
|
+
@raw_info ||= access_token.get("/rest/2.0/passport/users/getInfo", :params => {:uid => @uid}).parsed
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# You can pass +display+, +with_offical_account+ or +state+ params to the auth request, if
|
48
|
+
# you need to set them dynamically. You can also set these options
|
49
|
+
# in the OmniAuth config :authorize_params option.
|
50
|
+
#
|
51
|
+
# /auth/baidu?display=mobile&with_offical_account=1
|
52
|
+
#
|
53
|
+
def authorize_params
|
54
|
+
super.tap do |params|
|
55
|
+
%w[display with_offical_account state forcelogin].each do |v|
|
56
|
+
if request.params[v]
|
57
|
+
params[v.to_sym] = request.params[v]
|
58
|
+
|
59
|
+
# to support omniauth-oauth2's auto csrf protection
|
60
|
+
session['omniauth.state'] = params[:state] if v == 'state'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
OmniAuth.config.add_camelization "baidu", "Baidu"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/omniauth-baidu-oauth2/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "omniauth-baidu-oauth2"
|
6
|
+
spec.version = OmniAuth::BaiduOauth2::VERSION
|
7
|
+
spec.authors = ["gengda"]
|
8
|
+
spec.email = ["tony.keng@aliyun.com"]
|
9
|
+
spec.description = %q{OmniAuth Oauth2 strategy for baidu.com}
|
10
|
+
spec.summary = %q{OmniAuth Oauth2 strategy for baidu.com}
|
11
|
+
spec.homepage = "https://github.com/Tonykeng/omniauth-baidu-oauth2"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split("\n")
|
14
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency 'omniauth', '~> 1.0'
|
19
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.0'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-baidu-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gengda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-12 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:
|
43
|
+
- tony.keng@aliyun.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- lib/omniauth-baidu-oauth2.rb
|
52
|
+
- lib/omniauth-baidu-oauth2/version.rb
|
53
|
+
- lib/omniauth/strategies/baidu.rb
|
54
|
+
- omniauth-baidu-oauth2.gemspec
|
55
|
+
homepage: https://github.com/Tonykeng/omniauth-baidu-oauth2
|
56
|
+
licenses: []
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.0.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: OmniAuth Oauth2 strategy for baidu.com
|
78
|
+
test_files: []
|