-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.rb
57 lines (43 loc) · 1.39 KB
/
api.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'sinatra'
require 'pry'
require 'json'
class Message
attr_reader :messages
def initialize(messages)
@messages = {"Valid" => true, "Info": "IDX10214: Audience validation failed. Audiences: 'http://localhost:1337/'. Did not match: validationParameters.ValidAudience: 'null' or validationParameters.ValidAudiences: 'https://www.servsmart.servicemaster.com, http://mem0bscweb01d:60/, http://localhost:1337'"}
end
def to_json(options = {})
@messages.to_json(options)
end
end
class Rejection
attr_reader :rejection
def initialize(rejection)
@rejection = {"Valid" => false, "Info": "IDX10214: Audience validation failed. Audiences: 'http://localhost:1337/'. Did not match: validationParameters.ValidAudience: 'null' or validationParameters.ValidAudiences: 'https://www.servsmart.servicemaster.com, http://mem0bscweb01d:60/, http://localhost:1337'"}
end
def to_json(options = {})
@rejection.to_json(options)
end
end
messages = Message.new(messages)
rejection = Rejection.new(rejection)
before do
content_type :json
end
configure :development do
set :show_exceptions, :after_handler
end
not_found do
{ message: 'Not Found', code: 404 }.to_json
end
error do
{ message: env['sinatra.error'], code: 500 }.to_json
end
get '/validate-auth-header' do
if request.env['HTTP_AUTHORIZATION']
response.body = messages.to_json
else
response.body = rejection.to_json
halt 401
end
end