openbel-api 0.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemspec +65 -0
- data/CHANGELOG.md +22 -0
- data/INSTALL.md +19 -0
- data/INSTALL_RUBY.md +107 -0
- data/LICENSE +191 -0
- data/README.md +208 -0
- data/app/openbel/api/app.rb +83 -0
- data/app/openbel/api/config.rb +45 -0
- data/app/openbel/api/config.ru +3 -0
- data/app/openbel/api/helpers/pager.rb +109 -0
- data/app/openbel/api/middleware/auth.rb +112 -0
- data/app/openbel/api/resources/adapters/basic_json.rb +52 -0
- data/app/openbel/api/resources/annotation.rb +141 -0
- data/app/openbel/api/resources/base.rb +16 -0
- data/app/openbel/api/resources/completion.rb +89 -0
- data/app/openbel/api/resources/evidence.rb +115 -0
- data/app/openbel/api/resources/evidence_transform.rb +143 -0
- data/app/openbel/api/resources/function.rb +98 -0
- data/app/openbel/api/resources/match_result.rb +79 -0
- data/app/openbel/api/resources/namespace.rb +174 -0
- data/app/openbel/api/routes/annotations.rb +168 -0
- data/app/openbel/api/routes/authenticate.rb +108 -0
- data/app/openbel/api/routes/base.rb +326 -0
- data/app/openbel/api/routes/datasets.rb +519 -0
- data/app/openbel/api/routes/evidence.rb +330 -0
- data/app/openbel/api/routes/expressions.rb +560 -0
- data/app/openbel/api/routes/functions.rb +41 -0
- data/app/openbel/api/routes/namespaces.rb +382 -0
- data/app/openbel/api/routes/root.rb +39 -0
- data/app/openbel/api/schemas.rb +34 -0
- data/app/openbel/api/schemas/annotation_collection.schema.json +20 -0
- data/app/openbel/api/schemas/annotation_resource.schema.json +36 -0
- data/app/openbel/api/schemas/annotation_value_collection.schema.json +21 -0
- data/app/openbel/api/schemas/annotation_value_resource.schema.json +35 -0
- data/app/openbel/api/schemas/completion_collection.schema.json +21 -0
- data/app/openbel/api/schemas/completion_resource.schema.json +146 -0
- data/app/openbel/api/schemas/evidence.schema.json +198 -0
- data/app/openbel/api/schemas/evidence_collection.schema.json +98 -0
- data/app/openbel/api/schemas/evidence_resource.schema.json +29 -0
- data/app/openbel/api/schemas/namespace_value_collection.schema.json +21 -0
- data/app/openbel/api/schemas/namespace_value_resource.schema.json +43 -0
- data/app/openbel/api/util.rb +11 -0
- data/bin/openbel-api +78 -0
- data/bin/openbel-config +46 -0
- data/config/async_evidence.rb +12 -0
- data/config/async_jena.rb +14 -0
- data/config/config.yml +31 -0
- data/config/server_config.rb +184 -0
- data/lib/openbel/api/cache/cache.rb +30 -0
- data/lib/openbel/api/config/config.rb +33 -0
- data/lib/openbel/api/evidence/api.rb +39 -0
- data/lib/openbel/api/evidence/facet_api.rb +18 -0
- data/lib/openbel/api/evidence/facet_filter.rb +83 -0
- data/lib/openbel/api/evidence/mongo.rb +247 -0
- data/lib/openbel/api/evidence/mongo_facet.rb +105 -0
- data/lib/openbel/api/helpers/dependency_graph.rb +52 -0
- data/lib/openbel/api/model/rdf_resource.rb +74 -0
- data/lib/openbel/api/plugin/cache/kyotocabinet.rb +85 -0
- data/lib/openbel/api/plugin/configure_plugins.rb +97 -0
- data/lib/openbel/api/plugin/evidence/evidence.rb +58 -0
- data/lib/openbel/api/plugin/plugin.rb +99 -0
- data/lib/openbel/api/plugin/plugin_manager.rb +20 -0
- data/lib/openbel/api/plugin/plugin_repository.rb +60 -0
- data/lib/openbel/api/storage/cache_proxy.rb +74 -0
- data/lib/openbel/api/storage/triple_storage.rb +43 -0
- metadata +379 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'bel'
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module OpenBEL
|
5
|
+
module Resource
|
6
|
+
module MatchResults
|
7
|
+
|
8
|
+
class MatchResultSerializer < BaseSerializer
|
9
|
+
adapter Oat::Adapters::HAL
|
10
|
+
|
11
|
+
schema do
|
12
|
+
type :match_result
|
13
|
+
properties do |p|
|
14
|
+
p.match_text item.snippet
|
15
|
+
p.rdf_uri item.uri
|
16
|
+
p.rdf_scheme_uri item.scheme_uri
|
17
|
+
p.identifier item.identifier
|
18
|
+
p.name item.pref_label
|
19
|
+
|
20
|
+
# Do not have alt_labels property from FTS index.
|
21
|
+
# p.synonyms item.alt_labels
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class MatchResultResourceSerializer < BaseSerializer
|
27
|
+
adapter Oat::Adapters::HAL
|
28
|
+
|
29
|
+
schema do
|
30
|
+
type :'match_result'
|
31
|
+
properties do |p|
|
32
|
+
collection :match_results, item, MatchResultSerializer
|
33
|
+
end
|
34
|
+
|
35
|
+
# link :self, link_self(item.first[:short_form])
|
36
|
+
end
|
37
|
+
|
38
|
+
# private
|
39
|
+
#
|
40
|
+
# def link_self(id)
|
41
|
+
# {
|
42
|
+
# :type => :function,
|
43
|
+
# :href => "#{base_url}/api/functions/#{id}"
|
44
|
+
# }
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
|
48
|
+
class MatchResultCollectionSerializer < BaseSerializer
|
49
|
+
adapter Oat::Adapters::HAL
|
50
|
+
|
51
|
+
schema do
|
52
|
+
type :'match_result_collection'
|
53
|
+
properties do |p|
|
54
|
+
collection :match_results, item, MatchResultSerializer
|
55
|
+
end
|
56
|
+
|
57
|
+
# link :self, link_self
|
58
|
+
# link :start, link_start(item[0][:short_form])
|
59
|
+
end
|
60
|
+
|
61
|
+
# private
|
62
|
+
#
|
63
|
+
# def link_self
|
64
|
+
# {
|
65
|
+
# :type => :'function_collection',
|
66
|
+
# :href => "#{base_url}/api/functions"
|
67
|
+
# }
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# def link_start(first_function)
|
71
|
+
# {
|
72
|
+
# :type => :function,
|
73
|
+
# :href => "#{base_url}/api/functions/#{first_function}"
|
74
|
+
# }
|
75
|
+
# end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module OpenBEL
|
4
|
+
module Resource
|
5
|
+
module Namespaces
|
6
|
+
|
7
|
+
VOCABULARY_RDF = 'http://www.openbel.org/vocabulary/'
|
8
|
+
|
9
|
+
class NamespaceValueSearchResult < BEL::Resource::NamespaceValue
|
10
|
+
|
11
|
+
def match_text=(match_text)
|
12
|
+
@match_text = match_text
|
13
|
+
end
|
14
|
+
|
15
|
+
def match_text
|
16
|
+
@match_text
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class NamespaceSerializer < BaseSerializer
|
21
|
+
# adapter Oat::Adapters::HAL
|
22
|
+
schema do
|
23
|
+
type :namespace
|
24
|
+
property :rdf_uri, item.uri.to_s
|
25
|
+
property :name, item.prefLabel
|
26
|
+
property :prefix, item.prefix
|
27
|
+
property :domain, item.domain
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class NamespaceResourceSerializer < BaseSerializer
|
32
|
+
adapter Oat::Adapters::HAL
|
33
|
+
schema do
|
34
|
+
type :namespace
|
35
|
+
property :namespace, item
|
36
|
+
link :self, link_self(item)
|
37
|
+
link :collection, link_collection
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def link_self(item)
|
43
|
+
{
|
44
|
+
:type => :namespace,
|
45
|
+
:href => "#{base_url}/api/namespaces/#{item[:prefix]}"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def link_collection
|
50
|
+
{
|
51
|
+
:type => :namespace_collection,
|
52
|
+
:href => "#{base_url}/api/namespaces"
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class NamespaceCollectionSerializer < BaseSerializer
|
58
|
+
adapter Oat::Adapters::HAL
|
59
|
+
schema do
|
60
|
+
type :namespace_collection
|
61
|
+
property :namespace_collection, item
|
62
|
+
link :self, link_self
|
63
|
+
link :start, link_start
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def link_self
|
69
|
+
{
|
70
|
+
:type => :namespace_collection,
|
71
|
+
:href => "#{base_url}/api/namespaces"
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def link_start
|
76
|
+
{
|
77
|
+
:type => :start,
|
78
|
+
:href => "#{base_url}/api/namespaces/values"
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class NamespaceValueSerializer < BaseSerializer
|
84
|
+
#adapter Oat::Adapters::HAL
|
85
|
+
schema do
|
86
|
+
type :namespace_value
|
87
|
+
property :rdf_uri, item.uri.to_s
|
88
|
+
property :type, [item.type].flatten.map(&:to_s)
|
89
|
+
property :identifier, item.identifier
|
90
|
+
property :name, item.prefLabel
|
91
|
+
property :title, item.title
|
92
|
+
property :species, item.fromSpecies
|
93
|
+
entity :namespace, item.namespace, NamespaceSerializer
|
94
|
+
|
95
|
+
# Support inclusion of the matched text when annotation values are filtered by
|
96
|
+
# a full-text search.
|
97
|
+
if item.match_text
|
98
|
+
property :match_text, item.match_text
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class NamespaceValueResourceSerializer < BaseSerializer
|
104
|
+
adapter Oat::Adapters::HAL
|
105
|
+
schema do
|
106
|
+
parts = URI(item.delete(:rdf_uri)).path.split('/')[3..-1]
|
107
|
+
namespace_id = parts[0]
|
108
|
+
namespace_value_id = parts.join('/')
|
109
|
+
|
110
|
+
type :namespace_value
|
111
|
+
property :namespace_value, item
|
112
|
+
link :self, link_self(namespace_value_id)
|
113
|
+
link :collection, link_namespace(namespace_id)
|
114
|
+
link :equivalents, link_equivalents(namespace_value_id)
|
115
|
+
link :orthologs, link_orthologs(namespace_value_id)
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def link_self(id)
|
121
|
+
{
|
122
|
+
:type => :namespace_value,
|
123
|
+
:href => "#{base_url}/api/namespaces/#{id}"
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def link_namespace(id)
|
128
|
+
{
|
129
|
+
:type => :namespace,
|
130
|
+
:href => "#{base_url}/api/namespaces/#{id}"
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
def link_equivalents(id)
|
135
|
+
{
|
136
|
+
:type => :namespace_value_collection,
|
137
|
+
:href => "#{base_url}/api/namespaces/#{id}/equivalents"
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
def link_orthologs(id)
|
142
|
+
{
|
143
|
+
:type => :namespace_value_collection,
|
144
|
+
:href => "#{base_url}/api/namespaces/#{id}/orthologs"
|
145
|
+
}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class NamespaceValueCollectionSerializer < BaseSerializer
|
150
|
+
adapter Oat::Adapters::HAL
|
151
|
+
schema do
|
152
|
+
type :namespace_value_collection
|
153
|
+
property :namespace_value_collection, item
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class ValueEquivalenceSerializer < BaseSerializer
|
158
|
+
adapter Oat::Adapters::HAL
|
159
|
+
schema do
|
160
|
+
type :value_equivalence
|
161
|
+
property :value, item.value
|
162
|
+
property :type, item.type ? item.type.sub(VOCABULARY_RDF, '') : nil
|
163
|
+
property :identifier, item.identifier
|
164
|
+
property :title, item.title
|
165
|
+
property :species, item.fromSpecies
|
166
|
+
property :namespace_uri, item.inScheme
|
167
|
+
|
168
|
+
property :value_equivalence_collection, item.equivalences, NamespaceValueSerializer
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
# vim: ts=2 sw=2
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'bel'
|
2
|
+
|
3
|
+
module OpenBEL
|
4
|
+
module Routes
|
5
|
+
|
6
|
+
class Annotations < Base
|
7
|
+
include BEL::Language
|
8
|
+
|
9
|
+
SORTED_FUNCTIONS = FUNCTIONS.values.uniq.sort_by { |fx|
|
10
|
+
fx[:short_form]
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(app)
|
14
|
+
super
|
15
|
+
|
16
|
+
# RdfRepository using Jena.
|
17
|
+
@rr = BEL::RdfRepository.plugins[:jena].create_repository(
|
18
|
+
:tdb_directory => OpenBEL::Settings[:resource_rdf][:jena][:tdb_directory]
|
19
|
+
)
|
20
|
+
|
21
|
+
# Annotations using RdfRepository
|
22
|
+
@annotations = BEL::Resource::Annotations.new(@rr)
|
23
|
+
|
24
|
+
# Resource Search using SQLite.
|
25
|
+
@search = BEL::Resource::Search.plugins[:sqlite].create_search(
|
26
|
+
:database_file => OpenBEL::Settings[:resource_search][:sqlite][:database_file]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
options '/api/annotations' do
|
31
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
32
|
+
status 200
|
33
|
+
end
|
34
|
+
|
35
|
+
options '/api/annotations/values' do
|
36
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
37
|
+
status 200
|
38
|
+
end
|
39
|
+
|
40
|
+
options '/api/annotations/:annotation' do
|
41
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
42
|
+
status 200
|
43
|
+
end
|
44
|
+
|
45
|
+
options '/api/annotations/:annotation/values' do
|
46
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
47
|
+
status 200
|
48
|
+
end
|
49
|
+
|
50
|
+
options '/api/annotations/:annotation/values/:value' do
|
51
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
52
|
+
status 200
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/api/annotations' do
|
56
|
+
annotations = @annotations.each.to_a
|
57
|
+
halt 404 if not annotations or annotations.empty?
|
58
|
+
|
59
|
+
render_collection(
|
60
|
+
annotations.sort { |x,y|
|
61
|
+
x.prefLabel.to_s <=> y.prefLabel.to_s
|
62
|
+
},
|
63
|
+
:annotation
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
get '/api/annotations/values' do
|
68
|
+
start = (params[:start] || 0).to_i
|
69
|
+
size = (params[:size] || -1).to_i
|
70
|
+
size = -1 if size <= 0
|
71
|
+
faceted = as_bool(params[:faceted])
|
72
|
+
halt 501 if faceted
|
73
|
+
|
74
|
+
filter_hash = Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) }
|
75
|
+
filter_params = CGI::parse(env["QUERY_STRING"])['filter']
|
76
|
+
filter_params.each do |filter|
|
77
|
+
filter = read_filter(filter)
|
78
|
+
halt 400 unless ['category', 'name', 'value'].all? { |f| filter.include? f}
|
79
|
+
filter_hash[filter['category']][filter['name']] = filter['value']
|
80
|
+
end
|
81
|
+
|
82
|
+
halt 404 unless filter_hash['fts']['search'].is_a?(String)
|
83
|
+
match = filter_hash['fts']['search']
|
84
|
+
halt 404 unless match.length > 1
|
85
|
+
|
86
|
+
match_results = @search.search(wildcard_match(match), :annotation_concept, nil, nil,
|
87
|
+
:start => start,
|
88
|
+
:size => size
|
89
|
+
).map { |result|
|
90
|
+
value = OpenBEL::Resource::Annotations::AnnotationValueSearchResult.new(@rr, result.uri)
|
91
|
+
value.match_text = result.snippet
|
92
|
+
value
|
93
|
+
}.to_a
|
94
|
+
|
95
|
+
halt 404 if not match_results or match_results.empty?
|
96
|
+
render_collection(
|
97
|
+
match_results,
|
98
|
+
:annotation_value,
|
99
|
+
:adapter => Oat::Adapters::BasicJson
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
get '/api/annotations/:annotation' do |annotation|
|
104
|
+
annotation = @annotations.find(annotation).first
|
105
|
+
halt 404 unless annotation
|
106
|
+
|
107
|
+
status 200
|
108
|
+
render_resource(annotation, :annotation)
|
109
|
+
end
|
110
|
+
|
111
|
+
get '/api/annotations/:annotation/values' do |annotation|
|
112
|
+
annotation = @annotations.find(annotation).first
|
113
|
+
halt 404 unless annotation
|
114
|
+
|
115
|
+
start = (params[:start] || 0).to_i
|
116
|
+
size = (params[:size] || -1).to_i
|
117
|
+
size = -1 if size <= 0
|
118
|
+
faceted = as_bool(params[:faceted])
|
119
|
+
halt 501 if faceted
|
120
|
+
|
121
|
+
filter_hash = Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) }
|
122
|
+
filter_params = CGI::parse(env["QUERY_STRING"])['filter']
|
123
|
+
filter_params.each do |filter|
|
124
|
+
filter = read_filter(filter)
|
125
|
+
halt 400 unless ['category', 'name', 'value'].all? { |f| filter.include? f}
|
126
|
+
filter_hash[filter['category']][filter['name']] = filter['value']
|
127
|
+
end
|
128
|
+
|
129
|
+
halt 404 unless filter_hash['fts']['search'].is_a?(String)
|
130
|
+
match = filter_hash['fts']['search']
|
131
|
+
halt 404 unless match.length > 1
|
132
|
+
|
133
|
+
match_results = @search.search(wildcard_match(match), :annotation_concept, annotation.uri.to_s, nil,
|
134
|
+
:start => start,
|
135
|
+
:size => size
|
136
|
+
).map { |result|
|
137
|
+
value = OpenBEL::Resource::Annotations::AnnotationValueSearchResult.new(@rr, result.uri)
|
138
|
+
value.match_text = result.snippet
|
139
|
+
value
|
140
|
+
}.to_a
|
141
|
+
|
142
|
+
halt 404 if not match_results or match_results.empty?
|
143
|
+
render_collection(
|
144
|
+
match_results,
|
145
|
+
:annotation_value,
|
146
|
+
:adapter => Oat::Adapters::BasicJson
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
get '/api/annotations/:annotation/values/:value' do |annotation, value|
|
151
|
+
annotation = @annotations.find(annotation).first
|
152
|
+
halt 404 unless annotation
|
153
|
+
|
154
|
+
value = annotation.find(value).first
|
155
|
+
halt 404 unless value
|
156
|
+
|
157
|
+
status 200
|
158
|
+
render_resource(
|
159
|
+
value,
|
160
|
+
:annotation_value,
|
161
|
+
:adapter => Oat::Adapters::BasicJson
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
# vim: ts=2 sw=2:
|
168
|
+
# encoding: utf-8
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
def current_host(env)
|
5
|
+
scheme = env['rack.url_scheme'] || 'http'
|
6
|
+
host = env['HTTP_HOST']
|
7
|
+
"#{scheme}://#{host}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_path(env)
|
11
|
+
scheme = env['rack.url_scheme'] || 'http'
|
12
|
+
host = env['HTTP_HOST']
|
13
|
+
path = env['PATH_INFO']
|
14
|
+
"#{scheme}://#{host}#{path}"
|
15
|
+
end
|
16
|
+
|
17
|
+
module OpenBEL
|
18
|
+
module Routes
|
19
|
+
|
20
|
+
class Authenticate < Base
|
21
|
+
|
22
|
+
get '/api/authenticate' do
|
23
|
+
state = params[:state]
|
24
|
+
code = params[:code]
|
25
|
+
if code.nil?
|
26
|
+
default_connection = OpenBEL::Settings[:auth][:default_connection]
|
27
|
+
default_auth_url = current_path(env) + "/#{default_connection}"
|
28
|
+
if not state.nil?
|
29
|
+
default_auth_url += "?state=#{state}"
|
30
|
+
end
|
31
|
+
redirect to(default_auth_url)
|
32
|
+
end
|
33
|
+
|
34
|
+
domain = OpenBEL::Settings[:auth][:domain]
|
35
|
+
id = OpenBEL::Settings[:auth][:id]
|
36
|
+
secret = OpenBEL::Settings[:auth][:secret]
|
37
|
+
|
38
|
+
callback_url = current_path(env)
|
39
|
+
payload = {
|
40
|
+
client_id: id,
|
41
|
+
client_secret: secret,
|
42
|
+
redirect_uri: callback_url,
|
43
|
+
code: code,
|
44
|
+
grant_type: :authorization_code
|
45
|
+
}
|
46
|
+
|
47
|
+
token_url = "https://#{domain}/oauth/token"
|
48
|
+
body = payload.to_json
|
49
|
+
|
50
|
+
begin
|
51
|
+
token_response = RestClient.post token_url, body,
|
52
|
+
:content_type => :json,
|
53
|
+
:accept => :json
|
54
|
+
rescue => e
|
55
|
+
hdrs = {'Content-Type' => 'application/json'}
|
56
|
+
msg = {error: e.response }
|
57
|
+
return [401, hdrs, [msg.to_json]]
|
58
|
+
end
|
59
|
+
|
60
|
+
token_response = JSON.parse(token_response)
|
61
|
+
access_token = token_response['access_token']
|
62
|
+
jwt = token_response['id_token']
|
63
|
+
|
64
|
+
user_url = "https://#{domain}/userinfo?access_token=#{access_token}"
|
65
|
+
begin
|
66
|
+
user_response = RestClient.get user_url, :accept => :json
|
67
|
+
rescue => e
|
68
|
+
hdrs = {'Content-Type' => 'application/json'}
|
69
|
+
msg = {error: e.response }
|
70
|
+
return [401, hdrs, [msg.to_json]]
|
71
|
+
end
|
72
|
+
|
73
|
+
email = JSON.parse(user_response)['email']
|
74
|
+
hdrs = {'Content-Type' => 'application/json'}
|
75
|
+
msg = {success: email}
|
76
|
+
cookies[:jwt] = jwt
|
77
|
+
if not state.nil?
|
78
|
+
redirect to(state + "?jwt=#{jwt}")
|
79
|
+
else
|
80
|
+
[200, hdrs, [msg.to_json]]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
get '/api/authenticate/:connection' do
|
85
|
+
state = params[:state]
|
86
|
+
redirect_setting = OpenBEL::Settings[:auth][:redirect]
|
87
|
+
connection = params[:connection]
|
88
|
+
redirect_uri = current_host(env) + '/api/authenticate'
|
89
|
+
auth_url = "#{redirect_setting}"
|
90
|
+
auth_url += "&redirect_uri=#{redirect_uri}"
|
91
|
+
auth_url += "&connection=#{connection}"
|
92
|
+
if not state.nil?
|
93
|
+
auth_url += "&state=#{state}"
|
94
|
+
end
|
95
|
+
redirect to(auth_url)
|
96
|
+
end
|
97
|
+
|
98
|
+
get '/api/authentication-enabled' do
|
99
|
+
enabled = OpenBEL::Settings[:auth][:enabled]
|
100
|
+
hdrs = {'Content-Type' => 'application/json'}
|
101
|
+
msg = {enabled: enabled}
|
102
|
+
return [200, hdrs, [msg.to_json]]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
# vim: ts=2 sw=2:
|
108
|
+
# encoding: utf-8
|