Class: Clavem::Server
- Inherits:
-
Object
- Object
- Clavem::Server
- Defined in:
- lib/clavem/server.rb
Overview
A class to handle oAuth callbacks on the browser via HTTP.
Constant Summary collapse
- TEMPLATE =
The template to send to the browser.
"<html>\n <head>\n <title>Clavem</title>\n </head>\n <body>\n %s\n </body>\n</html>\n EOTEMPLATE\n.freeze\n"
Instance Method Summary collapse
-
#initialize(authorizer) ⇒ Server
constructor
Creates a new server.
-
#process_http_request ⇒ Object
Save the token and sends a response back to the user.
Constructor Details
#initialize(authorizer) ⇒ Server
Creates a new server.
26 27 28 29 30 31 |
# File 'lib/clavem/server.rb', line 26 def initialize() = @i18n = Bovem::I18n.new(root: "clavem", path: ::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/") process_http_request end |
Instance Method Details
#process_http_request ⇒ Object
Save the token and sends a response back to the user.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/clavem/server.rb', line 34 def process_http_request server = create_server socket = server.accept # Get the request request = socket.gets.gsub(/^[A-Z]+\s(.+)\sHTTP.+$/, "\\1") querystring = Addressable::URI.parse(("%s%s" % [.callback_url, request]).strip).query_values # Send the response and close the socket send_response(socket) # Handle the token token = .response_handler.call(querystring) (token) server.close end |