omniauth-yoyow 0.1.0
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 +6 -0
- data/README.cn.md +85 -0
- data/README.md +87 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/omniauth-yoyow.rb +3 -0
- data/lib/omniauth-yoyow/version.rb +5 -0
- data/lib/omniauth/strategies/yoyow.rb +53 -0
- data/lib/omniauth/yoyow-middleware.rb +56 -0
- data/omniauth-yoyow.gemspec +30 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b73dc35a0c92976a77405764c899008245214aac
|
4
|
+
data.tar.gz: b59e04416549020f2485150abc8a4aa7e05d28f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f629c323627c61fa51687e5c0a7948da2a5be83c44acacc0bfd65f657de514dd845fe7be1d26da7401860b19e3f37eb4859b69634b9e24818cacd2f1f1433359
|
7
|
+
data.tar.gz: f958242347355307df26ca269febc008658552ff525f986044dbceedfbc5b305dac867c142c16d942f6a83e2615a70f99900b425b049df53b4780bf3e25778f3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.cn.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# OmniAuth YOYOW
|
2
|
+
|
3
|
+
[中文](./README.cn.md) [En](./README.md)
|
4
|
+
|
5
|
+
这是官方的OmniAuth YOYOW认证策略, 借助YOYOW的平台授权机制以实现账户授权认证. 在使用之前, 你需要一个平台账户[(如何成为平台)](https://github.com/yoyow-org/yoyow-node-sdk/tree/master/middleware#2-%E5%88%9B%E5%BB%BA%E5%B9%B3%E5%8F%B0), 并架设[YOYOW中间件服务](#架设中间件服务).
|
6
|
+
|
7
|
+
## 安装
|
8
|
+
|
9
|
+
在应用的Gemfile中添加:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-yoyow'
|
13
|
+
```
|
14
|
+
|
15
|
+
然后执行:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
或者手动安装:
|
20
|
+
|
21
|
+
$ gem install omniauth-yoyow
|
22
|
+
|
23
|
+
## 用法
|
24
|
+
|
25
|
+
将下方URL修改为YOYOW中间件的服务地址:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
use OmniAuth::Builder do
|
29
|
+
provider :yoyow, 'http://localhost:3000'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## 架设中间件服务
|
34
|
+
|
35
|
+
将中间件代码clone到本地:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
git clone https://github.com/yoyow-org/yoyow-node-sdk/tree/master/middleware
|
39
|
+
cd middleware
|
40
|
+
vim conf/config.js
|
41
|
+
```
|
42
|
+
|
43
|
+
在项目开发阶段, 可以借助YOYOW测试网进行测试, 待测试完成后再切换到正式网络.
|
44
|
+
|
45
|
+
测试网的配置示例如下:
|
46
|
+
|
47
|
+
```javascript
|
48
|
+
module.exports = {
|
49
|
+
// yoyow全节点api服务器地址(测试网)
|
50
|
+
apiServer: "ws://47.52.155.181:10011",
|
51
|
+
// 请求有效时间,单位s
|
52
|
+
secure_ageing: 120,
|
53
|
+
// 平台安全请求验证key 由平台自定义
|
54
|
+
secure_key: "",
|
55
|
+
// 平台所有者active私钥(可选)
|
56
|
+
active_key: "",
|
57
|
+
// 平台所有者零钱私钥(必需)
|
58
|
+
secondary_key: "",
|
59
|
+
// 平台所有者备注私钥(可选)
|
60
|
+
memo_key: "",
|
61
|
+
// 平台id(yoyow id)
|
62
|
+
platform_id: "",
|
63
|
+
// 转账是否使用积分
|
64
|
+
use_csaf: true,
|
65
|
+
// 转账是否转到余额 否则转到零钱
|
66
|
+
to_balance: false,
|
67
|
+
// 钱包授权页URL
|
68
|
+
wallet_url: "http://demo.yoyow.org:8000/#/authorize-service",
|
69
|
+
// 允许接入的IP列表
|
70
|
+
allow_ip: ["localhost", "127.0.0.1"]
|
71
|
+
};
|
72
|
+
```
|
73
|
+
|
74
|
+
正式网配置示例:
|
75
|
+
```javascript
|
76
|
+
module.exports = {
|
77
|
+
// yoyow全节点api服务器地址(正式网)
|
78
|
+
apiServer: "wss://wallet.yoyow.org/ws",
|
79
|
+
...
|
80
|
+
// 钱包授权页URL
|
81
|
+
wallet_url: "http://wallet.yoyow.org/#/authorize-service",
|
82
|
+
// 允许接入的IP列表
|
83
|
+
allow_ip: ["localhost", "127.0.0.1"]
|
84
|
+
};
|
85
|
+
```
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Omniauth YOYOW
|
2
|
+
|
3
|
+
[中文](./README.cn.md) [En](./README.md)
|
4
|
+
|
5
|
+
This is the official OmniAuth strategy for authenticating to YOYOW. To use it, a **platform** account is needed([what's platform](https://github.com/yoyow-org/yoyow-node-sdk/blob/master/middleware/README-EN.md#25-update-platform)), addtionally, you'll need to setup [yoyow-middleware](#setup-yoyow-middleware).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-yoyow'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install omniauth-yoyow
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Change the url to yoyow-middleware server address in following code.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
use OmniAuth::Builder do
|
29
|
+
provider :yoyow, 'http://localhost:3000'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Setup YOYOW Middleware
|
35
|
+
|
36
|
+
Clone the middleware code:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
git clone https://github.com/yoyow-org/yoyow-node-sdk/tree/master/middleware
|
40
|
+
cd middleware
|
41
|
+
vim conf/config.js
|
42
|
+
```
|
43
|
+
|
44
|
+
YOYOW test-net configuration is recommended while developing your applaction, you can switch it to main-net when production ready.
|
45
|
+
|
46
|
+
Sample config for test-net:
|
47
|
+
|
48
|
+
```javascript
|
49
|
+
module.exports = {
|
50
|
+
// yoyow full node api(test-net)
|
51
|
+
apiServer: "ws://47.52.155.181:10011",
|
52
|
+
// seconds before requests invaild
|
53
|
+
secure_ageing: 120,
|
54
|
+
// platform specified secure key
|
55
|
+
secure_key: "",
|
56
|
+
// active key of platform(optional)
|
57
|
+
active_key: "",
|
58
|
+
// secondary key of platform(required)
|
59
|
+
secondary_key: "",
|
60
|
+
// memo key of platform(optional)
|
61
|
+
memo_key: "",
|
62
|
+
// platform id(yoyow id)
|
63
|
+
platform_id: "",
|
64
|
+
// choose to use csaf when transfer token
|
65
|
+
use_csaf: true,
|
66
|
+
// transfer token to balance, otherwise to Tipping
|
67
|
+
to_balance: false,
|
68
|
+
// authorization URL
|
69
|
+
wallet_url: "http://demo.yoyow.org:8000/#/authorize-service",
|
70
|
+
// IP list allowed to access
|
71
|
+
allow_ip: ["localhost", "127.0.0.1"]
|
72
|
+
};
|
73
|
+
```
|
74
|
+
|
75
|
+
Sample config for main-net:
|
76
|
+
|
77
|
+
```javascript
|
78
|
+
module.exports = {
|
79
|
+
// yoyow full node api(main-net)
|
80
|
+
apiServer: "wss://wallet.yoyow.org/ws",
|
81
|
+
...
|
82
|
+
// authorization URL
|
83
|
+
wallet_url: "http://wallet.yoyow.org/#/authorize-service",
|
84
|
+
// IP list allowed to access
|
85
|
+
allow_ip: ["localhost", "127.0.0.1"]
|
86
|
+
};
|
87
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "omniauth/yoyow"
|
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
@@ -0,0 +1,53 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
class Yoyow
|
4
|
+
include OmniAuth::Strategy
|
5
|
+
class CallbackError < StandardError; end
|
6
|
+
args %i[auth_server]
|
7
|
+
|
8
|
+
option :auth_server, "http://localhost:3000"
|
9
|
+
|
10
|
+
# yoyow middleware
|
11
|
+
def middleware
|
12
|
+
@middleware ||= OmniAuth::YoyowMiddleware.new(options.auth_server)
|
13
|
+
end
|
14
|
+
|
15
|
+
def request_phase
|
16
|
+
redirect auth_url
|
17
|
+
end
|
18
|
+
|
19
|
+
def auth_url
|
20
|
+
middleware.get_auth_url(callback_url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def callback_url
|
24
|
+
full_host + script_name + callback_path
|
25
|
+
end
|
26
|
+
|
27
|
+
def callback_phase
|
28
|
+
yyw_id = request.params["yoyow"]
|
29
|
+
time = request.params["time"]
|
30
|
+
sign = request.params["sign"]
|
31
|
+
if ! middleware.verify_auth(yyw_id, time, sign)
|
32
|
+
raise CallbackError.new("invalid credential found.")
|
33
|
+
end
|
34
|
+
|
35
|
+
super
|
36
|
+
rescue CallbackError => e
|
37
|
+
fail!(:invalid_credential, e)
|
38
|
+
end
|
39
|
+
|
40
|
+
uid do
|
41
|
+
request.params["yoyow"]
|
42
|
+
end
|
43
|
+
|
44
|
+
info do
|
45
|
+
account = middleware.get_account(uid)
|
46
|
+
{
|
47
|
+
name: account[:name],
|
48
|
+
nickname: account[:name],
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
class YoyowMiddleware
|
7
|
+
attr_reader :resource
|
8
|
+
|
9
|
+
class MiddlewareRequestError < StandardError; end
|
10
|
+
|
11
|
+
def initialize(url)
|
12
|
+
unless url.start_with?('http')
|
13
|
+
url = 'http://' + url
|
14
|
+
end
|
15
|
+
@resource = Faraday.new(url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_auth_url(callback_url)
|
19
|
+
resp = get_platform_sign
|
20
|
+
auth_data = resp.slice(:sign, :time, :platform).merge({state: callback_url})
|
21
|
+
auth_url = [resp[:url], '?', URI.encode_www_form(auth_data)].join('')
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_account(uid)
|
25
|
+
_get '/api/v1/getAccount', uid: uid
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_platform_sign
|
29
|
+
_get '/auth/sign'
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify_auth(yyw_id, time, sign)
|
33
|
+
return false if yyw_id.nil? or time.nil? or sign.nil?
|
34
|
+
|
35
|
+
data = _get('/auth/verify', {
|
36
|
+
yoyow: yyw_id,
|
37
|
+
time: time,
|
38
|
+
sign: sign
|
39
|
+
})
|
40
|
+
data[:verify]
|
41
|
+
end
|
42
|
+
|
43
|
+
def _get(url, params={})
|
44
|
+
begin
|
45
|
+
resp = resource.get url, params
|
46
|
+
json = MultiJson.load resp.body, :symbolize_keys => true
|
47
|
+
raise MiddlewareRequestError.new(json[:message]) if json[:code] != 0
|
48
|
+
json[:data]
|
49
|
+
rescue MiddlewareRequestError => e
|
50
|
+
puts "Error occurs while accessing yoyow middleware: "
|
51
|
+
puts e.message
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "omniauth-yoyow/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-yoyow"
|
8
|
+
spec.version = Omniauth::Yoyow::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.authors = ["Bin Chen"]
|
11
|
+
spec.email = ["fengzhishuiwo@163.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Official OmniAuth strategy for yoyow.}
|
14
|
+
spec.description = %q{Official OmniAuth strategy for yoyow.}
|
15
|
+
spec.homepage = "https://coding.net/u/vianull/p/omniauth-yoyow/git"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
|
27
|
+
spec.add_dependency 'omniauth', '~> 1.5'
|
28
|
+
spec.add_dependency "multi_json"
|
29
|
+
spec.add_dependency "faraday"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-yoyow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bin Chen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-29 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: omniauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Official OmniAuth strategy for yoyow.
|
84
|
+
email:
|
85
|
+
- fengzhishuiwo@163.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- README.cn.md
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/omniauth-yoyow.rb
|
98
|
+
- lib/omniauth-yoyow/version.rb
|
99
|
+
- lib/omniauth/strategies/yoyow.rb
|
100
|
+
- lib/omniauth/yoyow-middleware.rb
|
101
|
+
- omniauth-yoyow.gemspec
|
102
|
+
homepage: https://coding.net/u/vianull/p/omniauth-yoyow/git
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.6.11
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Official OmniAuth strategy for yoyow.
|
126
|
+
test_files: []
|