class Conify::Sso
Attributes
external_uuid[RW]
proxy_port[RW]
timestamp[RW]
token[RW]
url[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/conify/sso.rb, line 8 def initialize(data) @external_uuid = data[:external_uuid] @external_username = data[:external_username] @salt = data['api']['sso_salt'] env = data.fetch('env', 'test') if @url = data['api'][env]['sso_url'] @use_post = true @proxy_port = find_available_port else @url = data['api'][env].chomp('/') end @timestamp = Time.now.to_i @token = make_token(@timestamp) end
Public Instance Methods
POST?()
click to toggle source
# File lib/conify/sso.rb, line 29 def POST? @use_post end
find_available_port()
click to toggle source
# File lib/conify/sso.rb, line 81 def find_available_port server = TCPServer.new('127.0.0.1', 0) server.addr[1] ensure server.close if server end
full_url()
click to toggle source
# File lib/conify/sso.rb, line 37 def full_url [ url, path, querystring ].join end
Also aliased as: get_url
make_token(t)
click to toggle source
# File lib/conify/sso.rb, line 51 def make_token(t) Digest::SHA1.hexdigest([external_uuid, @salt, t].join(':')) end
message()
click to toggle source
# File lib/conify/sso.rb, line 73 def message if self.POST? "POSTing #{query_data} to #{post_url} via proxy on port #{@proxy_port}" else "Opening #{full_url}" end end
path()
click to toggle source
# File lib/conify/sso.rb, line 25 def path self.POST? ? URI.parse(url).path : "/conflux/resources/#{external_uuid}" end
post_url()
click to toggle source
# File lib/conify/sso.rb, line 42 def post_url url end
query_data()
click to toggle source
# File lib/conify/sso.rb, line 60 def query_data query_params.map{|p| p.join('=')}.join('&') end
query_params()
click to toggle source
# File lib/conify/sso.rb, line 64 def query_params { 'id' => external_uuid, 'token' => @token, 'timestamp' => @timestamp.to_s, 'email' => @external_username } end
querystring()
click to toggle source
# File lib/conify/sso.rb, line 55 def querystring return '' unless @salt '?' + query_data end
sso_url()
click to toggle source
# File lib/conify/sso.rb, line 33 def sso_url self.POST? ? "http://localhost:#{@proxy_port}/" : full_url end
timestamp=(other)
click to toggle source
# File lib/conify/sso.rb, line 46 def timestamp=(other) @timestamp = other @token = make_token(@timestamp) end