Class: MojeID
- Inherits:
-
Object
- Object
- MojeID
- Defined in:
- lib/ruby-mojeid.rb
Instance Attribute Summary collapse
-
#fetch_request ⇒ Object
Returns the value of attribute fetch_request.
-
#fetch_response ⇒ Object
Returns the value of attribute fetch_response.
-
#moje_id_request ⇒ Object
Returns the value of attribute moje_id_request.
-
#moje_id_response ⇒ Object
Returns the value of attribute moje_id_response.
-
#realm ⇒ Object
Returns the value of attribute realm.
-
#return_to ⇒ Object
Returns the value of attribute return_to.
-
#xrds_result ⇒ Object
Returns the value of attribute xrds_result.
Class Method Summary collapse
-
.fetch_request(consumer, openid_identifier, request_type = :get) ⇒ Object
Prepare request for openid server .
-
.fetch_response(consumer, params, request, current_url, request_type = :get) ⇒ Object
Get response from openid server.
Instance Method Summary collapse
-
#add_additional_data(data = {}) ⇒ Object
Add additional data to request Accept hash like => ‘yes’.
-
#add_attributes(attributes = []) ⇒ Object
Add attributes you would like to read about user, to request.
-
#data ⇒ Object
Return data parsed to Hash, if it is a “fetch_response” with request_type == :get, else return blank Hash.
-
#get_attribute_value(attribute) ⇒ Object
Return a value of attribute, when you recieve a data from openid server.
-
#html_markup(realm, return_to, immediate = false, form_tag_attrs = {}) ⇒ Object
Get a complete HTML document that autosubmits the request to the IDP with javascript.
-
#identifier ⇒ Object
Return the openid identifier like fullname.mojeid.cz.
-
#message ⇒ Object
Return the response message.
-
#redirect_url(immediate = false) ⇒ Object
Return the url you have to redirect after you compose your request.
-
#response_status ⇒ Object
Return the status of openid server response the statuses are : * OpenID::Consumer::FAILURE * OpenID::Consumer::SUCCESS * OpenID::Consumer::SETUP_NEEDED * OpenID::Consumer::CANCEL.
-
#send_redirect?(immediate = false) ⇒ Boolean
Should this OpenID authentication request be sent as a HTTP redirect or as a POST (form submission)?.
- #set_fetch_request_by_type(request_type) ⇒ Object
- #set_response_by_type(request_type) ⇒ Object
-
#update_attributes(data = {}) ⇒ Object
Add attributes and they values which you would like to update user profile, to request.
Instance Attribute Details
#fetch_request ⇒ Object
Returns the value of attribute fetch_request.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def fetch_request @fetch_request end |
#fetch_response ⇒ Object
Returns the value of attribute fetch_response.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def fetch_response @fetch_response end |
#moje_id_request ⇒ Object
Returns the value of attribute moje_id_request.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def moje_id_request @moje_id_request end |
#moje_id_response ⇒ Object
Returns the value of attribute moje_id_response.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def moje_id_response @moje_id_response end |
#realm ⇒ Object
Returns the value of attribute realm.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def realm @realm end |
#return_to ⇒ Object
Returns the value of attribute return_to.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def return_to @return_to end |
#xrds_result ⇒ Object
Returns the value of attribute xrds_result.
7 8 9 |
# File 'lib/ruby-mojeid.rb', line 7 def xrds_result @xrds_result end |
Class Method Details
.fetch_request(consumer, openid_identifier, request_type = :get) ⇒ Object
Prepare request for openid server
openid_identifier is user identifier like fullname.mojeid.cz consumer is object of OpenID::Consumer class.
here is example how to create consumer
-
store = OpenID::Store::Memcache.new(MemCache.new(‘localhost:11211’))
-
@consumer = OpenID::Consumer.new(session, store)
You can choose if you will be read data or store data by request_type param
-
request_type == :get mean that you will be read data about user
-
request_type == :put mean that you will be store data about user
here is example how to create MojeID fetch request
-
@moje_id = MojeID.fetch_request(@consumer, ‘fullname.mojeid.cz’)
25 26 27 28 29 30 |
# File 'lib/ruby-mojeid.rb', line 25 def self.fetch_request(consumer, openid_identifier, request_type = :get) moje_id = MojeID.new moje_id.moje_id_request = consumer.begin(openid_identifier) moje_id.set_fetch_request_by_type(request_type) moje_id end |
.fetch_response(consumer, params, request, current_url, request_type = :get) ⇒ Object
Get response from openid server
-
consumer is object of OpenID::Consumer class, like in the fetch_request method
-
params are a params from request which openid server send to you
-
request is a request object from controller. It is necessary to remove dirty params
-
current_url is url of action which recieve the openid server response
-
with request_type you say, if this response become from get request or put request
here is example how to create MojeID fetch response
-
@moje_id = MojeID.fetch_response(@consumer, params, request, url_for(:action => ‘complete_update_data’, :only_path => false), :put)
43 44 45 46 47 48 49 |
# File 'lib/ruby-mojeid.rb', line 43 def self.fetch_response(consumer, params, request, current_url, request_type = :get) moje_id = MojeID.new parameters = params.reject{|k,v| request.path_parameters[k]} moje_id.fetch_response = consumer.complete(parameters, current_url) moje_id.set_response_by_type(request_type) if moje_id.response_status == OpenID::Consumer::SUCCESS moje_id end |
Instance Method Details
#add_additional_data(data = {}) ⇒ Object
Add additional data to request Accept hash like => ‘yes’
94 95 96 97 |
# File 'lib/ruby-mojeid.rb', line 94 def add_additional_data(data = {}) data.each{|k,v| moje_id_request.return_to_args[k.to_s] = v} bundle_to_request end |
#add_attributes(attributes = []) ⇒ Object
Add attributes you would like to read about user, to request. You can pass attribute as array and change options like ns_alias or require.
-
example: @moje_id.add_attributes([‘axschema.org/namePerson’, nil, false])
-
or simple : @moje_id.add_attributes(‘axschema.org/namePerson’)
82 83 84 |
# File 'lib/ruby-mojeid.rb', line 82 def add_attributes(attributes = []) attributes.each{ |attribute| attribute.is_a?(Array) ? add_attribute(attribute[0], attribute[1], attribute[2]) : add_attribute(attribute)} end |
#data ⇒ Object
Return data parsed to Hash, if it is a “fetch_response” with request_type == :get, else return blank Hash
74 75 76 |
# File 'lib/ruby-mojeid.rb', line 74 def data (!moje_id_response.nil? && moje_id_response.respond_to?('data') ) ? moje_id_response.data : {} end |
#get_attribute_value(attribute) ⇒ Object
Return a value of attribute, when you recieve a data from openid server
115 116 117 |
# File 'lib/ruby-mojeid.rb', line 115 def get_attribute_value(attribute) data[attribute] end |
#html_markup(realm, return_to, immediate = false, form_tag_attrs = {}) ⇒ Object
Get a complete HTML document that autosubmits the request to the IDP with javascript.
110 111 112 |
# File 'lib/ruby-mojeid.rb', line 110 def html_markup(realm, return_to, immediate = false, form_tag_attrs = {}) moje_id_request.html_markup(realm, return_to, immediate, form_tag_attrs) end |
#identifier ⇒ Object
Return the openid identifier like fullname.mojeid.cz
64 65 66 |
# File 'lib/ruby-mojeid.rb', line 64 def identifier fetch_response.display_identifier end |
#message ⇒ Object
Return the response message
69 70 71 |
# File 'lib/ruby-mojeid.rb', line 69 def fetch_response. end |
#redirect_url(immediate = false) ⇒ Object
Return the url you have to redirect after you compose your request
105 106 107 |
# File 'lib/ruby-mojeid.rb', line 105 def redirect_url(immediate = false) moje_id_request.redirect_url(realm, return_to, immediate) end |
#response_status ⇒ Object
Return the status of openid server response the statuses are :
-
OpenID::Consumer::FAILURE
-
OpenID::Consumer::SUCCESS
-
OpenID::Consumer::SETUP_NEEDED
-
OpenID::Consumer::CANCEL
59 60 61 |
# File 'lib/ruby-mojeid.rb', line 59 def response_status fetch_response.status end |
#send_redirect?(immediate = false) ⇒ Boolean
Should this OpenID authentication request be sent as a HTTP redirect or as a POST (form submission)?
100 101 102 |
# File 'lib/ruby-mojeid.rb', line 100 def send_redirect?(immediate = false) moje_id_request.send_redirect?(realm, return_to, immediate) end |
#set_fetch_request_by_type(request_type) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/ruby-mojeid.rb', line 120 def set_fetch_request_by_type(request_type) self.fetch_request = case request_type when :get then OpenID::AX::FetchRequest.new when :put then OpenID::AX::StoreRequest.new end end |
#set_response_by_type(request_type) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/ruby-mojeid.rb', line 127 def set_response_by_type(request_type) self.moje_id_response = case request_type when :get then OpenID::AX::FetchResponse.from_success_response(self.fetch_response) when :put then OpenID::AX::StoreResponse.from_success_response(self.fetch_response) end end |
#update_attributes(data = {}) ⇒ Object
Add attributes and they values which you would like to update user profile, to request. Accept hash like href="http://axschema.org/namePerson">axschema.org/namePerson’ => ‘my new great name’
88 89 90 |
# File 'lib/ruby-mojeid.rb', line 88 def update_attributes(data = {}) data.each{ |attribute, value| set_attribute(attribute, value)} end |