bjond-api 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +15 -2
- data/VERSION +1 -1
- data/app/controllers/bjondservices_controller.rb +2 -21
- data/bjond-api.gemspec +6 -6
- data/db/migrate/20160801184749_rename_registration_idin_bjond_service_to_bjond_registration_id.rb +5 -0
- data/lib/bjond-api.rb +21 -1
- data/lib/bjond-app/engine.rb +0 -7
- data/lib/bjond-jwt.rb +22 -0
- metadata +23 -22
- data/app/helpers/bjond_registrations_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1b8c62b62da444bbae2b0a5e7045c329ab00e9
|
4
|
+
data.tar.gz: 400eae6848c9dd1943a0dd9d69b565682021684d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 221bcf5d4e198a9f47918986c121d9de4480547541e503eb49287da490c059e7f5c7f418db01e1fd8d13aa2f7344e5cd1257d383139e4711c4bd510da7f8c6e8
|
7
|
+
data.tar.gz: 7f95fbcdd9583273dbc53ff52a12b35a8be2ecbca2df26b04847863af4e83b8f25cadfadbaa582701265ce49d1a74086c65c28077a60514625ab2c40d638fcb7
|
data/README.rdoc
CHANGED
@@ -4,6 +4,12 @@ A rubygem wrapper for the Bjönd API.
|
|
4
4
|
|
5
5
|
This gem also contains an engine with endpoints that are made to interface with Bjond server-core.
|
6
6
|
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
gem install 'bjond-api'
|
10
|
+
|
11
|
+
For specific version info visit the gem page[https://rubygems.org/gems/bjond-api].
|
12
|
+
|
7
13
|
== Creating a Bjond Integration App
|
8
14
|
|
9
15
|
To create a Bjond App using the Ruby on Rails framework, perform the following actions within your Rails application.
|
@@ -27,8 +33,6 @@ To install necessary migrations, add this to your Rails' application.rb file -
|
|
27
33
|
|
28
34
|
rake db:migrate
|
29
35
|
|
30
|
-
The `config.paths['db/migrate']` line can be removed once the migrations are copied.
|
31
|
-
|
32
36
|
(5) Generate Configuration Files
|
33
37
|
|
34
38
|
To get you started, generate a config file by running the following command:
|
@@ -70,4 +74,13 @@ Again, BJOND_APP_ENCRYPTION_KEY can be changed. It just needs to match the value
|
|
70
74
|
- register_app
|
71
75
|
|
72
76
|
|
77
|
+
- fire_event
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
== Environment Variables
|
82
|
+
|
83
|
+
- BJOND_ADAPTER_AUDIENCE
|
84
|
+
- BJOND_ADAPTER_SUBJECT
|
85
|
+
|
73
86
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -2,6 +2,7 @@ class BjondservicesController < ApplicationController
|
|
2
2
|
|
3
3
|
require 'bjond-api'
|
4
4
|
require 'syruppay_jose'
|
5
|
+
include BjondJwtHelper
|
5
6
|
|
6
7
|
skip_before_filter :verify_authenticity_token, :only => [:get_schema, :register_group_endpoint, :configure_group_endpoint]
|
7
8
|
|
@@ -31,7 +32,7 @@ class BjondservicesController < ApplicationController
|
|
31
32
|
|
32
33
|
def register_group_endpoint
|
33
34
|
registration = BjondRegistration.find_registration_by_remote_ip(request.remote_ip)
|
34
|
-
service = BjondService.find_or_initialize_by(:group_id => params[:groupid], :
|
35
|
+
service = BjondService.find_or_initialize_by(:group_id => params[:groupid], :bjond_registration_id => registration.id)
|
35
36
|
if (service.endpoint != params[:endpoint])
|
36
37
|
service.endpoint = params[:endpoint]
|
37
38
|
service.save
|
@@ -60,24 +61,4 @@ class BjondservicesController < ApplicationController
|
|
60
61
|
render :json => jwt_encode_payload(payload.to_json, bjond_registration)
|
61
62
|
end
|
62
63
|
|
63
|
-
private
|
64
|
-
def jwt_encode_payload(json, bjond_registration)
|
65
|
-
payload = {
|
66
|
-
:json => json,
|
67
|
-
:iss => 'Bjönd, Inc.',
|
68
|
-
:aud => ENV['BJOND_ADAPTER_AUDIENCE'],
|
69
|
-
:exp => Time.now.to_i + 10*3600,
|
70
|
-
:nbf => Time.now.to_i - 2*3600,
|
71
|
-
:sub => ENV['BJOND_ADAPTER_SUBJECT']
|
72
|
-
}.to_json
|
73
|
-
header = {:alg => 'A128KW', :enc => 'A128CBC-HS256'}
|
74
|
-
return SyrupPay::JsonEncryptionCompactSerialization.serialization(Base64.decode64(bjond_registration.encryption_key), header, payload)
|
75
|
-
end
|
76
|
-
|
77
|
-
def jwt_decode_payload_and_return_json(token, bjond_registration)
|
78
|
-
claims_json = SyrupPay::CompactDeserialization.deserialization(Base64.decode64(bjond_registration.encryption_key), token)
|
79
|
-
claims = JSON.parse(claims_json)
|
80
|
-
return JSON.parse(claims['json'][0])
|
81
|
-
end
|
82
|
-
|
83
64
|
end
|
data/bjond-api.gemspec
CHANGED
@@ -2,16 +2,14 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bjond-api 0.0.4 ruby lib
|
6
5
|
|
7
6
|
Gem::Specification.new do |s|
|
8
7
|
s.name = "bjond-api"
|
9
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
10
9
|
|
11
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
11
|
s.authors = ["Blake Rego"]
|
14
|
-
s.date = "2016-
|
12
|
+
s.date = "2016-08-01"
|
15
13
|
s.description = "Rails engine that provides communication between Bj\u{f6}nd Server Core and a client app."
|
16
14
|
s.email = "blake.rego@bjondinc.com"
|
17
15
|
s.executables = ["rails"]
|
@@ -34,7 +32,6 @@ Gem::Specification.new do |s|
|
|
34
32
|
"app/controllers/bjond_registrations_controller.rb",
|
35
33
|
"app/controllers/bjondservices_controller.rb",
|
36
34
|
"app/helpers/.keep",
|
37
|
-
"app/helpers/bjond_registrations_helper.rb",
|
38
35
|
"app/mailers/.keep",
|
39
36
|
"app/models/.keep",
|
40
37
|
"app/models/bjond_registration.rb",
|
@@ -58,6 +55,7 @@ Gem::Specification.new do |s|
|
|
58
55
|
"db/migrate/20160727144938_add_host_and_ip_to_bjond_registrations.rb",
|
59
56
|
"db/migrate/20160727191615_create_bjond_services.rb",
|
60
57
|
"db/migrate/20160727194217_add_registration_id_to_bjond_service.rb",
|
58
|
+
"db/migrate/20160801184749_rename_registration_idin_bjond_service_to_bjond_registration_id.rb",
|
61
59
|
"lib/bjond-api.rb",
|
62
60
|
"lib/bjond-app-config.rb",
|
63
61
|
"lib/bjond-app-definition.rb",
|
@@ -65,12 +63,14 @@ Gem::Specification.new do |s|
|
|
65
63
|
"lib/bjond-consequence.rb",
|
66
64
|
"lib/bjond-event.rb",
|
67
65
|
"lib/bjond-field.rb",
|
66
|
+
"lib/bjond-jwt.rb",
|
68
67
|
"lib/generators/initializer_generator.rb",
|
69
68
|
"lib/generators/templates/initializer.rb"
|
70
69
|
]
|
71
70
|
s.homepage = "http://github.com/Bjond/bjond-integration-gem"
|
72
71
|
s.licenses = ["GPL"]
|
73
|
-
s.
|
72
|
+
s.require_paths = ["lib"]
|
73
|
+
s.rubygems_version = "2.0.14"
|
74
74
|
s.summary = "Interface that facilitates communication with Bj\u{f6}nd servers."
|
75
75
|
|
76
76
|
if s.respond_to? :specification_version then
|
data/lib/bjond-api.rb
CHANGED
@@ -5,17 +5,37 @@ require 'bjond-field'
|
|
5
5
|
require 'faraday'
|
6
6
|
require 'bjond-app/engine'
|
7
7
|
require 'bjond-app-config'
|
8
|
+
require 'bjond-jwt'
|
9
|
+
include BjondJwt
|
8
10
|
|
9
11
|
module BjondApi
|
10
12
|
|
13
|
+
##
|
14
|
+
# Registers the given integration_app with a bjond-server.
|
11
15
|
def self.register_app(integration_app, bjondhost=ENV['BJOND_SERVER'])
|
12
16
|
conn = Faraday.new(:url => bjondhost)
|
13
17
|
return conn.post do |req|
|
14
|
-
req.url '/server-core/services/integrationmanager/register
|
18
|
+
req.url '/server-core/services/integrationmanager/register'
|
15
19
|
req.headers['Content-Type'] = 'application/json'
|
16
20
|
req.body = integration_app.to_json
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
24
|
+
##
|
25
|
+
# Fires events to all bjond_registrations
|
26
|
+
def fire_event(bjond_registration, payload)
|
27
|
+
services = BjondService.where(:bjond_registration_id => bjond_registration.id)
|
28
|
+
connections = []
|
29
|
+
services.each do |bjond_svc|
|
30
|
+
conn = Faraday.new(:url => bjond_svc.endpoint)
|
31
|
+
conn.post do |req|
|
32
|
+
req.headers['Content-Type'] = 'application/json'
|
33
|
+
req.body = BjondJwt::jwt_encode_payload(payload, bjond_registration)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
return connections
|
38
|
+
end
|
39
|
+
|
20
40
|
end
|
21
41
|
|
data/lib/bjond-app/engine.rb
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
module BjondApi
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
initializer :append_migrations do |app|
|
4
|
-
unless app.root.to_s.match root.to_s
|
5
|
-
config.paths["db/migrate"].expanded.each do |expanded_path|
|
6
|
-
app.config.paths["db/migrate"] << expanded_path
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
3
|
end
|
11
4
|
end
|
data/lib/bjond-jwt.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'syruppay_jose'
|
2
|
+
|
3
|
+
module BjondJwt
|
4
|
+
def jwt_encode_payload(json, bjond_registration)
|
5
|
+
payload = {
|
6
|
+
:json => json,
|
7
|
+
:iss => 'Bjönd, Inc.',
|
8
|
+
:aud => ENV['BJOND_ADAPTER_AUDIENCE'],
|
9
|
+
:exp => Time.now.to_i + 10*3600,
|
10
|
+
:nbf => Time.now.to_i - 2*3600,
|
11
|
+
:sub => ENV['BJOND_ADAPTER_SUBJECT']
|
12
|
+
}.to_json
|
13
|
+
header = {:alg => 'A128KW', :enc => 'A128CBC-HS256'}
|
14
|
+
return SyrupPay::JsonEncryptionCompactSerialization.serialization(Base64.decode64(bjond_registration.encryption_key), header, payload)
|
15
|
+
end
|
16
|
+
|
17
|
+
def jwt_decode_payload_and_return_json(token, bjond_registration)
|
18
|
+
claims_json = SyrupPay::CompactDeserialization.deserialization(Base64.decode64(bjond_registration.encryption_key), token)
|
19
|
+
claims = JSON.parse(claims_json)
|
20
|
+
return JSON.parse(claims['json'][0])
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,101 +1,101 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bjond-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Rego
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.2.4
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '4.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 4.2.4
|
30
|
-
- -
|
30
|
+
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: jeweler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 2.0.1
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '2.0'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 2.0.1
|
50
|
-
- -
|
50
|
+
- - ~>
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: faraday
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- -
|
57
|
+
- - ~>
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: 0.9.2
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ~>
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 0.9.2
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: syruppay_jose
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ~>
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '1.0'
|
74
74
|
type: :runtime
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- -
|
78
|
+
- - ~>
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '1.0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: attr_encrypted
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- -
|
85
|
+
- - '>='
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: 3.0.3
|
88
|
-
- -
|
88
|
+
- - ~>
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '3.0'
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 3.0.3
|
98
|
-
- -
|
98
|
+
- - ~>
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '3.0'
|
101
101
|
description: Rails engine that provides communication between Bjönd Server Core and
|
@@ -122,7 +122,6 @@ files:
|
|
122
122
|
- app/controllers/bjond_registrations_controller.rb
|
123
123
|
- app/controllers/bjondservices_controller.rb
|
124
124
|
- app/helpers/.keep
|
125
|
-
- app/helpers/bjond_registrations_helper.rb
|
126
125
|
- app/mailers/.keep
|
127
126
|
- app/models/.keep
|
128
127
|
- app/models/bjond_registration.rb
|
@@ -146,6 +145,7 @@ files:
|
|
146
145
|
- db/migrate/20160727144938_add_host_and_ip_to_bjond_registrations.rb
|
147
146
|
- db/migrate/20160727191615_create_bjond_services.rb
|
148
147
|
- db/migrate/20160727194217_add_registration_id_to_bjond_service.rb
|
148
|
+
- db/migrate/20160801184749_rename_registration_idin_bjond_service_to_bjond_registration_id.rb
|
149
149
|
- lib/bjond-api.rb
|
150
150
|
- lib/bjond-app-config.rb
|
151
151
|
- lib/bjond-app-definition.rb
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/bjond-consequence.rb
|
154
154
|
- lib/bjond-event.rb
|
155
155
|
- lib/bjond-field.rb
|
156
|
+
- lib/bjond-jwt.rb
|
156
157
|
- lib/generators/initializer_generator.rb
|
157
158
|
- lib/generators/templates/initializer.rb
|
158
159
|
homepage: http://github.com/Bjond/bjond-integration-gem
|
@@ -165,17 +166,17 @@ require_paths:
|
|
165
166
|
- lib
|
166
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
167
168
|
requirements:
|
168
|
-
- -
|
169
|
+
- - '>='
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
173
|
requirements:
|
173
|
-
- -
|
174
|
+
- - '>='
|
174
175
|
- !ruby/object:Gem::Version
|
175
176
|
version: '0'
|
176
177
|
requirements: []
|
177
178
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.0.14
|
179
180
|
signing_key:
|
180
181
|
specification_version: 4
|
181
182
|
summary: Interface that facilitates communication with Bjönd servers.
|