Sha256: 042bbbd1832aab8b62a2b5c164299297c9483eea4d4614233fea2a4ceb4bc96a
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require 'net/https' require 'json' require 'netrc' class AuthenticationController < MVCLI::Controller requires :user def login #Check if they're already logged in #if(they're logged in) # prompt("you sure bout that?") login_info = user username = login_info.name password = login_info.password uri = URI('https://identity.api.rackspacecloud.com/v2.0/tokens') req = Net::HTTP::Post.new(uri) req['Content-Type'] = 'application/json' req.body = {auth: {passwordCredentials: {username: username, password: password}}}.to_json res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |https| https.request req end user_info = Map(JSON.parse res.body) uri = URI("https://identity.api.rackspacecloud.com/v2.0/users/#{user_info.access.user.id}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials") req = Net::HTTP::Get.new(uri, initheader = {'X-Auth-Token' => user_info.access.token.id}) req['Content-Type'] = 'application/json' res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |https| https.request req end user_credentials = Map(JSON.parse res.body) netrc = Netrc.read netrc['api.rackspace.com'] = username, user_credentials["RAX-KSKEY:apiKeyCredentials"].apiKey netrc.save user_info end def logout n = Netrc.read n.delete 'api.rackspace.com' n.save end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rumm-0.0.3 | app/controllers/authentication_controller.rb |