class Openplacos::Connection_auth_code
Attributes
token[R]
Public Class Methods
new(url_, name_, scope_, id_, port_)
click to toggle source
Open a connection to openplacos server Please give:
-
opos url
-
an application name that identify the client oath2 talking
-
a scope, typically [“read”, “write”, “user”]
-
an optionnal id, to manage several clients
-
port of openplacos server
# File lib/openplacos/libclient.rb, line 181 def initialize(url_, name_, scope_, id_, port_) @url = url_ @name = name_ @scope = scope_ @redirect_uri = "http://0.0.0.0:#{port_}" @port = port_ dir_config = "#{ENV['HOME']}/.openplacos" if !Dir.exists?(dir_config) Dir.mkdir(dir_config) end # config saved to avoir re-grant at each connection @file_config = "#{dir_config}/#{@name}-#{id_}.yaml" load_config if @token_params[@url].nil? #get token -- first time register create_client grant get_token save_config else # persistant mode create_client recreate_token end end
Private Instance Methods
get_auth_code()
click to toggle source
# File lib/openplacos/libclient.rb, line 223 def get_auth_code() # listen to get the auth code server = TCPServer.new(@port) re=/code=(.*)&scope/ authcode = nil while (session = server.accept) request = session.gets authcode = re.match(request) if !authcode.nil? session.print "HTTP/1.1 200/OK\rContent-type: text/html\r\n\r\n" session.puts "<h1>Auth successfull</h1>" session.close break end end authcode[1] end
get_token()
click to toggle source
# File lib/openplacos/libclient.rb, line 241 def get_token() begin @token = @client.auth_code.get_token(@auth_code, {:redirect_uri => @redirect_uri},{:mode=>:header, :header_format=>"OAuth %s", :param_name=>"oauth_token"}) rescue => e puts e.description Process.exit 42 end end
grant()
click to toggle source
display a message indicating url for grant this method can be overloaded by client depending it’s interface with user
# File lib/openplacos/libclient.rb, line 212 def grant () go_to_url = get_grant_url("code") puts "***************" puts "Please open your web browser and got to :" puts go_to_url puts "***************" @auth_code = get_auth_code end