Class: Identizer::Handlers::Auth0Management
- Inherits:
-
Base
- Object
- Base
- Identizer::Handlers::Auth0Management
show all
- Defined in:
- lib/identizer/handlers/auth0_management.rb
Overview
Emulates the slice of the Auth0 Management API a brokering app uses to provision/deprovision SSO: creating and deleting applications (clients) and SAML connections. Reached by pointing the Auth0 domain at Identizer; the management bearer token (from the client_credentials grant) is accepted as-is.
Created objects are kept in memory so list/delete behave consistently within a running process.
Instance Method Summary
collapse
Methods included from Responses
#amz_json, #escape_html, #html, #json, #no_content, #not_found, #notice_page, #redirect, #xml
Constructor Details
Returns a new instance of Auth0Management.
13
14
15
16
17
18
|
# File 'lib/identizer/handlers/auth0_management.rb', line 13
def initialize(context)
super
@clients = {}
@connections = {}
@mutex = Mutex.new end
|
Instance Method Details
#create_client(request) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/identizer/handlers/auth0_management.rb', line 20
def create_client(request)
client = parse_json(request).merge(
"client_id" => SecureRandom.alphanumeric(32),
"client_secret" => SecureRandom.alphanumeric(64)
)
@mutex.synchronize { @clients[client["client_id"]] = client }
json(201, client)
end
|
#create_connection(request) ⇒ Object
44
45
46
47
48
|
# File 'lib/identizer/handlers/auth0_management.rb', line 44
def create_connection(request)
connection = parse_json(request).merge("id" => "con_#{SecureRandom.alphanumeric(24)}")
@mutex.synchronize { @connections[connection["id"]] = connection }
json(201, connection)
end
|
#delete_client(_request, id) ⇒ Object
35
36
37
38
|
# File 'lib/identizer/handlers/auth0_management.rb', line 35
def delete_client(_request, id)
@mutex.synchronize { @clients.delete(id) }
no_content
end
|
#delete_connection(_request, id) ⇒ Object
56
57
58
59
|
# File 'lib/identizer/handlers/auth0_management.rb', line 56
def delete_connection(_request, id)
@mutex.synchronize { @connections.delete(id) }
no_content
end
|
#list_clients(_request) ⇒ Object
40
41
42
|
# File 'lib/identizer/handlers/auth0_management.rb', line 40
def list_clients(_request)
json(200, @mutex.synchronize { @clients.values })
end
|
#list_connections(_request) ⇒ Object
61
62
63
|
# File 'lib/identizer/handlers/auth0_management.rb', line 61
def list_connections(_request)
json(200, @mutex.synchronize { @connections.values })
end
|
#update_client(request, id) ⇒ Object
29
30
31
32
33
|
# File 'lib/identizer/handlers/auth0_management.rb', line 29
def update_client(request, id)
body = parse_json(request)
updated = @mutex.synchronize { @clients[id] = (@clients[id] || { "client_id" => id }).merge(body) }
json(200, updated)
end
|
#update_connection(request, id) ⇒ Object
50
51
52
53
54
|
# File 'lib/identizer/handlers/auth0_management.rb', line 50
def update_connection(request, id)
body = parse_json(request)
updated = @mutex.synchronize { @connections[id] = (@connections[id] || { "id" => id }).merge(body) }
json(200, updated)
end
|