Class: LiveContacts
- Inherits:
-
Object
- Object
- LiveContacts
- Defined in:
- lib/live_contacts.rb
Overview
Goto msm.live.com/app/default.aspx to configure your application
For testin purposes in my example me.diary.com is a virtual host in the /etc/hosts file pointing at 127.0.0.1
The APP_DETAILS hash has most of all the information I have registered my application with
Example rails controller code:
require ‘live_contacts’
protect_from_forgery :except => :windows_live_authentication
APP_DETAILS =
:application_name => 'RLiveContacts',
:app_id => '0016BFFD80013411',
:secret => 'b623d64e8f1d18bfe8b281d385ad461c1e8bbebb',
:security_algorithm => 'wsignin1.0',
:return_url => 'http://me.diary.com:3000/home/windows_live_authentication',
:privacy_policy_url => "http://me.diary.com:3000/privacy",
:application_verifier_required => false
def windows_live_authentication
lc = LiveContacts.new(APP_DETAILS)
if request.post?
lc.(params)
xml = lc.retrieve_address_book_xml
render :xml => xml and return
else
redirect_to lc.generate_delegation_url and return
end
end
Constant Summary collapse
- VERSION =
'0.0.6'
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Live application attibutes.
-
#application_name ⇒ Object
Live application attibutes.
-
#application_verifier_required ⇒ Object
Live application attibutes.
-
#consent_token ⇒ Object
readonly
delegated authentication attributes.
-
#cryptkey ⇒ Object
readonly
delegated authentication attributes.
-
#decrypted_token ⇒ Object
readonly
delegated authentication attributes.
-
#delt ⇒ Object
readonly
delegated authentication attributes.
-
#eact ⇒ Object
readonly
delegated authentication attributes.
-
#int_lid ⇒ Object
readonly
delegated authentication attributes.
-
#lid ⇒ Object
readonly
delegated authentication attributes.
-
#parsed_decrypted_token ⇒ Object
readonly
delegated authentication attributes.
-
#parsed_token ⇒ Object
readonly
delegated authentication attributes.
-
#privacy_policy_url ⇒ Object
Live application attibutes.
-
#return_url ⇒ Object
Live application attibutes.
-
#secret ⇒ Object
Live application attibutes.
-
#security_algorithm ⇒ Object
Live application attibutes.
-
#timestamp ⇒ Object
Live application attibutes.
Instance Method Summary collapse
-
#generate_delegation_url ⇒ Object
Step 2 - Get authentication consent from Live.com.
-
#initialize(app_details) ⇒ LiveContacts
constructor
Step 1 - Initialize the object with the corrent details.
-
#process_consent_params(params) ⇒ Object
Step 3 - Process what was returned from Step 2, so we are ready to talk to the API.
-
#retrieve_address_book_xml ⇒ Object
Step 4 - Actually request some information from the API, at the moment, simply just getting all contacts from the address book TODO timeout, error responses.
Constructor Details
#initialize(app_details) ⇒ LiveContacts
Step 1 - Initialize the object with the corrent details
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/live_contacts.rb', line 53 def initialize(app_details) self.application_name = app_details[:application_name] self.app_id = app_details[:app_id] self.secret = app_details[:secret] self.security_algorithm = app_details[:security_algorithm] self.return_url = app_details[:return_url] self.privacy_policy_url = app_details[:privacy_policy_url] self.application_verifier_required = app_details[:application_verifier_required] # mainly used for testing purposes to check the signature generated self. = app_details[:timestamp] end |
Instance Attribute Details
#app_id ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def app_id @app_id end |
#application_name ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def application_name @application_name end |
#application_verifier_required ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def application_verifier_required @application_verifier_required end |
#consent_token ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def end |
#cryptkey ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def cryptkey @cryptkey end |
#decrypted_token ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def decrypted_token @decrypted_token end |
#delt ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def delt @delt end |
#eact ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def eact @eact end |
#int_lid ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def int_lid @int_lid end |
#lid ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def lid @lid end |
#parsed_decrypted_token ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def parsed_decrypted_token @parsed_decrypted_token end |
#parsed_token ⇒ Object (readonly)
delegated authentication attributes
50 51 52 |
# File 'lib/live_contacts.rb', line 50 def parsed_token @parsed_token end |
#privacy_policy_url ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def privacy_policy_url @privacy_policy_url end |
#return_url ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def return_url @return_url end |
#secret ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def secret @secret end |
#security_algorithm ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def security_algorithm @security_algorithm end |
#timestamp ⇒ Object
Live application attibutes
47 48 49 |
# File 'lib/live_contacts.rb', line 47 def end |
Instance Method Details
#generate_delegation_url ⇒ Object
Step 2 - Get authentication consent from Live.com
67 68 69 70 71 |
# File 'lib/live_contacts.rb', line 67 def generate_delegation_url url = "https://consent.live.com/Delegation.aspx?RU=#{self.return_url}&ps=Contacts.View&pl=#{self.privacy_policy_url}" url += "&app=#{generate_app_verifier}" if self.application_verifier_required url end |
#process_consent_params(params) ⇒ Object
Step 3 - Process what was returned from Step 2, so we are ready to talk to the API
74 75 76 77 78 79 80 |
# File 'lib/live_contacts.rb', line 74 def (params) return false unless params['ResponseCode'] == 'RequestApproved' return false unless params['ConsentToken'] = false = true if (params['ConsentToken']) end |
#retrieve_address_book_xml ⇒ Object
Step 4 - Actually request some information from the API, at the moment, simply just getting all contacts from the address book TODO timeout, error responses
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/live_contacts.rb', line 84 def retrieve_address_book_xml return unless url = URI.parse("https://livecontacts.services.live.com" + "/users/@C@" + self.int_lid.to_s + "/REST/LiveContacts/Contacts") req = Net::HTTP::Get.new(url.path) req.add_field('Authorization', "DelegatedToken dt=\"" + self.delt + "\"") req.set_content_type('application/xml', :charset => 'utf-8') con = Net::HTTP.new(url.host, url.port) con.use_ssl = true res = con.start { |http| http.request(req) } res.body end |