Class: Tide::API::AuthServer
- Inherits:
-
Object
- Object
- Tide::API::AuthServer
- Defined in:
- lib/tide/api/auth_server.rb
Overview
Receives an authorization grant code from the OAuth2 callback.
Constant Summary collapse
- CLIENT_ID =
This is the ID shown in the authorization page of the mobile app
'tide-api-gem'.freeze
- RESPONSE =
Complete HTTP response
"HTTP/1.1 200 OK\r\n" \ "Content-Type: text/plain\r\n" \ "Content-Length: 31\r\n" \ "Connection: close\r\n" \ "\r\n" \ "You can now close this window.\n".freeze
Instance Method Summary collapse
-
#initialize ⇒ AuthServer
constructor
A new instance of AuthServer.
-
#run ⇒ String
Runs a tiny HTTP server to receive OAuth2 callbacks.
Constructor Details
#initialize ⇒ AuthServer
Returns a new instance of AuthServer.
18 19 20 21 |
# File 'lib/tide/api/auth_server.rb', line 18 def initialize @server = TCPServer.new('localhost', 0) @port = server.addr[1] end |
Instance Method Details
#run ⇒ String
Runs a tiny HTTP server to receive OAuth2 callbacks.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tide/api/auth_server.rb', line 27 def run puts 'Waiting for the authorization code...' request_auth_nonce socket = server.accept auth_nonce = extract_auth_nonce(socket.gets) puts 'Authorization code received.' socket.print RESPONSE socket.close auth_nonce end |