nx-weibo-sso 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +13 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nx/version.rb +5 -0
- data/lib/nx/weibo-sso.rb +69 -0
- data/lib/nx-weibo-sso.rb +2 -0
- data/nx-weibo-sso.gemspec +34 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f727b2936e28be581433c5aeabb363e007ed000ed3c2e6624761686ceb9b92c
|
4
|
+
data.tar.gz: 43ef4d69a2f8208dbd56cf04afeab553ce5aebe3f6fe514a4109a39e3d2bd8a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc00dee6f0254271bee0b46f747c06ac5298abc9443983823762a39a4e88beed4e23205ead5814e84a2054cf611cac5d9ebba0fec3f8ddd8c54ef471208a9d5f
|
7
|
+
data.tar.gz: 15f4ef09c12b14ed36d3549d7b5e2770b6635376f3ca57d81a140b360500aab5bbde7081761095236a44baf786d342ed7c640c9f7504269a88932d4322cc459b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nx-weibo-sso"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nx/version.rb
ADDED
data/lib/nx/weibo-sso.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "uri"
|
3
|
+
require "cgi"
|
4
|
+
require "json"
|
5
|
+
require "base64"
|
6
|
+
require "net/http"
|
7
|
+
|
8
|
+
PRELOGIN_JSONP_RE = /{(.*)}/
|
9
|
+
|
10
|
+
module Nx
|
11
|
+
class WeiboSso
|
12
|
+
def self.token(username, password)
|
13
|
+
# url login:
|
14
|
+
url_prelogin = "https://login.sina.com.cn/sso/prelogin.php"
|
15
|
+
url_login = "https://login.sina.com.cn/sso/login.php"
|
16
|
+
|
17
|
+
# prepare data:
|
18
|
+
su = Base64.strict_encode64(username.sub("@", "%40"))
|
19
|
+
|
20
|
+
# regexp
|
21
|
+
prelogin_data = {
|
22
|
+
entry: "sso",
|
23
|
+
callback: "sinaSSOController.preloginCallBack",
|
24
|
+
su: su,
|
25
|
+
rsakt: "mod",
|
26
|
+
client: "ssologin.js(v1.4.15)",
|
27
|
+
_: Time.now.to_i.to_s,
|
28
|
+
}
|
29
|
+
|
30
|
+
## prelogin:
|
31
|
+
res = open("#{url_prelogin}?#{URI.encode_www_form(prelogin_data)}")
|
32
|
+
prelogin_response = JSON.parse PRELOGIN_JSONP_RE.match(res.read)[0]
|
33
|
+
|
34
|
+
pwdkey = prelogin_response["servertime"].to_s + "\t" + prelogin_response["nonce"].to_s + "\n" + password.to_s
|
35
|
+
pub = OpenSSL::PKey::RSA::new
|
36
|
+
pub.set_key(OpenSSL::BN.new(prelogin_response["pubkey"], 16), 65537, nil)
|
37
|
+
sp = pub.public_encrypt(pwdkey).unpack("H*").first
|
38
|
+
|
39
|
+
data = {
|
40
|
+
"entry" => "weibo",
|
41
|
+
"gateway" => 1,
|
42
|
+
"from" => "",
|
43
|
+
"savestate" => 30,
|
44
|
+
"useticket" => 0,
|
45
|
+
"pagerefer" => "",
|
46
|
+
"vsnf" => 1,
|
47
|
+
"service" => "sso",
|
48
|
+
"pwencode" => "rsa2",
|
49
|
+
"sr" => "1920 * 1200",
|
50
|
+
"encoding" => "UTF-8",
|
51
|
+
"cdult" => 3,
|
52
|
+
"domain" => "sina.com.cn",
|
53
|
+
"returntype" => "TEXT",
|
54
|
+
}
|
55
|
+
|
56
|
+
data.merge!(prelogin_response).merge!({
|
57
|
+
"su" => su,
|
58
|
+
"sp" => sp,
|
59
|
+
"prelt" => 56,
|
60
|
+
})
|
61
|
+
|
62
|
+
login_response = Net::HTTP.post_form(URI(url_login), data)
|
63
|
+
url_ticket = JSON.parse(login_response.body)["crossDomainUrlList"][0]
|
64
|
+
weibo_sso_res = Net::HTTP.get_response(URI(url_ticket))
|
65
|
+
|
66
|
+
weibo_sso_res.get_fields("set-cookie")[0]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/nx-weibo-sso.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nx/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nx-weibo-sso"
|
8
|
+
spec.version = Nx::WeiboSso::VERSION
|
9
|
+
spec.authors = ["afeiship"]
|
10
|
+
spec.email = ["1290657123@qq.com"]
|
11
|
+
|
12
|
+
spec.description = %q{Weibo sso gem for nx.}
|
13
|
+
spec.summary = %q{Weibo sso gem.}
|
14
|
+
spec.homepage = "https://github.com/afeiship/nx-weibo-sso"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nx-weibo-sso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- afeiship
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Weibo sso gem for nx.
|
42
|
+
email:
|
43
|
+
- 1290657123@qq.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bin/console
|
53
|
+
- bin/setup
|
54
|
+
- lib/nx-weibo-sso.rb
|
55
|
+
- lib/nx/version.rb
|
56
|
+
- lib/nx/weibo-sso.rb
|
57
|
+
- nx-weibo-sso.gemspec
|
58
|
+
homepage: https://github.com/afeiship/nx-weibo-sso
|
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
|
+
rubygems_version: 3.1.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Weibo sso gem.
|
80
|
+
test_files: []
|