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
- TEMPLATE =
The template to send to the browser.
<<~EOTEMPLATE .freeze
Instance Method Summary (collapse)
-
- (Server) initialize(authorizer)
constructor
Creates a new server.
-
- (Object) process_http_request
Save the token and sends a response back to the user.
Constructor Details
- (Server) initialize(authorizer)
Creates a new server.
26 27 28 29 30 31 |
# File 'lib/clavem/server.rb', line 26 def initialize() @authorizer = @i18n = Bovem::I18n.new(root: "clavem", path: ::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/") process_http_request end |
Instance Method Details
- (Object) process_http_request
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" % [@authorizer.callback_url, request]).strip).query_values # Send the response and close the socket send_response(socket) # Handle the token token = @authorizer.response_handler.call(querystring) (token) server.close end |