myinfo 0.1.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/myinfo.rb +7 -2
- data/lib/myinfo/v3/api.rb +12 -1
- data/lib/myinfo/v3/person.rb +6 -4
- data/lib/myinfo/v3/person_basic.rb +6 -4
- data/lib/myinfo/v3/response.rb +13 -2
- data/lib/myinfo/v3/token.rb +5 -3
- data/lib/myinfo/version.rb +7 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f99857f69be28ab49c3407d0c1d048863fcd7a10716130dc94a0966ec1e27c
|
4
|
+
data.tar.gz: 849a140d5d9d89e8021734daaf77105cf06abc23a6b2f0ba01710e9e8459aa7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc61a48e588d2316fbb3fcbb36e92cc2f3f2e81fd82ad7330445ad18d7f4fcb86aff4cc48f63dc5cd862261a277aabafff878354032167762152da9872085830
|
7
|
+
data.tar.gz: 2c223679d8acddebf56821af5423e7f795e791617d6daf47189087ec7be62b0bac6ee7d52d0f19b77dbed3a0ece2627b897e4aedffb428fe1d536ac8e8f3ab1f
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
config.app_id = ''
|
16
16
|
config.client_id = ''
|
17
17
|
config.client_secret = ''
|
18
|
-
config.base_url = 'test.api.myinfo.gov.sg'
|
18
|
+
config.base_url = 'test.api.myinfo.gov.sg'
|
19
19
|
config.redirect_uri = 'https://localhost:3001/callback'
|
20
20
|
config.public_facing = true
|
21
21
|
config.private_key = File.read(Rails.root.join('private_key_location'))
|
@@ -55,7 +55,7 @@ result = MyInfo::V3::Person.call(access_token: response.data) if response.succes
|
|
55
55
|
config.app_id = ''
|
56
56
|
config.client_id = ''
|
57
57
|
config.client_secret = ''
|
58
|
-
config.base_url = 'test.api.myinfo.gov.sg'
|
58
|
+
config.base_url = 'test.api.myinfo.gov.sg'
|
59
59
|
config.redirect_uri = 'https://localhost:3001/callback'
|
60
60
|
config.singpass_eservice_id = 'MYINFO-CONSENTPLATFORM'
|
61
61
|
config.private_key = File.read(Rails.root.join('private_key_location'))
|
data/lib/myinfo.rb
CHANGED
@@ -29,9 +29,10 @@ module MyInfo
|
|
29
29
|
|
30
30
|
# Configuration to set various properties needed to use MyInfo
|
31
31
|
class Configuration
|
32
|
-
attr_accessor :singpass_eservice_id, :app_id, :
|
33
|
-
:
|
32
|
+
attr_accessor :singpass_eservice_id, :app_id, :client_id, :proxy, :private_key, :public_cert, :client_secret,
|
33
|
+
:redirect_uri
|
34
34
|
|
35
|
+
attr_reader :base_url
|
35
36
|
attr_writer :public_facing, :sandbox
|
36
37
|
|
37
38
|
def initialize
|
@@ -40,6 +41,10 @@ module MyInfo
|
|
40
41
|
@proxy = { address: nil, port: nil }
|
41
42
|
end
|
42
43
|
|
44
|
+
def base_url=(url)
|
45
|
+
@base_url = url.sub('https://', '').split('/').first
|
46
|
+
end
|
47
|
+
|
43
48
|
def base_url_with_protocol
|
44
49
|
"https://#{base_url}"
|
45
50
|
end
|
data/lib/myinfo/v3/api.rb
CHANGED
@@ -17,6 +17,16 @@ module MyInfo
|
|
17
17
|
raise NotImplementedError, 'abstract'
|
18
18
|
end
|
19
19
|
|
20
|
+
def slug
|
21
|
+
''
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
yield
|
26
|
+
rescue StandardError => e
|
27
|
+
Response.new(success: false, data: e)
|
28
|
+
end
|
29
|
+
|
20
30
|
def http_method
|
21
31
|
'GET'
|
22
32
|
end
|
@@ -50,6 +60,8 @@ module MyInfo
|
|
50
60
|
else
|
51
61
|
Response.new(success: false, data: "#{response.code} - #{response.body}")
|
52
62
|
end
|
63
|
+
rescue StandardError => e
|
64
|
+
Response.new(success: false, data: e)
|
53
65
|
end
|
54
66
|
|
55
67
|
protected
|
@@ -63,7 +75,6 @@ module MyInfo
|
|
63
75
|
end
|
64
76
|
|
65
77
|
def decode_jws(jws)
|
66
|
-
# TODO: verify signature
|
67
78
|
JWT.decode(jws, public_key, true, algorithm: 'RS256').first
|
68
79
|
end
|
69
80
|
|
data/lib/myinfo/v3/person.rb
CHANGED
@@ -14,11 +14,13 @@ module MyInfo
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call
|
17
|
-
|
18
|
-
|
17
|
+
super do
|
18
|
+
headers = header(params: params, access_token: access_token)
|
19
|
+
endpoint_url = "/#{slug}?#{params.to_query}"
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
response = http.request_get(endpoint_url, headers)
|
22
|
+
parse_response(response)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def slug
|
@@ -15,11 +15,13 @@ module MyInfo
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def call
|
18
|
-
|
19
|
-
|
18
|
+
super do
|
19
|
+
headers = header(params: params)
|
20
|
+
endpoint_url = "/#{slug}?#{params.to_query}"
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
response = http.request_get(endpoint_url, headers)
|
23
|
+
parse_response(response)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def slug
|
data/lib/myinfo/v3/response.rb
CHANGED
@@ -4,11 +4,22 @@ module MyInfo
|
|
4
4
|
module V3
|
5
5
|
# Simple response wrapper
|
6
6
|
class Response
|
7
|
-
|
7
|
+
attr_reader :data
|
8
8
|
|
9
9
|
def initialize(success:, data:)
|
10
10
|
@success = success
|
11
|
-
|
11
|
+
|
12
|
+
if data.is_a?(StandardError)
|
13
|
+
@data = data.message
|
14
|
+
@exception = true
|
15
|
+
else
|
16
|
+
@data = data
|
17
|
+
@exception = false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def exception?
|
22
|
+
@exception
|
12
23
|
end
|
13
24
|
|
14
25
|
def success?
|
data/lib/myinfo/v3/token.rb
CHANGED
@@ -12,10 +12,12 @@ module MyInfo
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call
|
15
|
-
|
16
|
-
|
15
|
+
super do
|
16
|
+
headers = header(params: params).merge({ 'Content-Type' => 'application/x-www-form-urlencoded' })
|
17
|
+
response = http.request_post("/#{slug}", params.to_param, headers)
|
17
18
|
|
18
|
-
|
19
|
+
parse_response(response)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def http_method
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myinfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lim Yao Jie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwe
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 6.1.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 6.1.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.11'
|
139
139
|
description: Rails wrapper for MyInfo API
|
140
|
-
email:
|
140
|
+
email: lim_yao_jie@tech.gov.sg
|
141
141
|
executables: []
|
142
142
|
extensions: []
|
143
143
|
extra_rdoc_files: []
|
@@ -153,7 +153,8 @@ files:
|
|
153
153
|
- lib/myinfo/v3/person_basic.rb
|
154
154
|
- lib/myinfo/v3/response.rb
|
155
155
|
- lib/myinfo/v3/token.rb
|
156
|
-
|
156
|
+
- lib/myinfo/version.rb
|
157
|
+
homepage: https://github.com/GovTechSG/myinfo-rails
|
157
158
|
licenses:
|
158
159
|
- MIT
|
159
160
|
metadata: {}
|
@@ -172,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
- !ruby/object:Gem::Version
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
|
-
rubygems_version: 3.1.
|
176
|
+
rubygems_version: 3.1.2
|
176
177
|
signing_key:
|
177
178
|
specification_version: 4
|
178
|
-
summary: MyInfo
|
179
|
+
summary: Rails wrapper for MyInfo API
|
179
180
|
test_files: []
|