Class: MojeID
Defined Under Namespace
Classes: DiscoveryFailure
Constant Summary collapse
- MOJEID_ENDPOINT =
"https://mojeid.cz/endpoint/"
- MOJEID_ENDPOINT_TEST =
"https://mojeid.fred.nic.cz/endpoint/"
Constants included from MojeIDAttributes
MojeIDAttributes::AVAILABLE_ATTRIBUTES
Instance Attribute Summary collapse
-
#auth_request ⇒ Object
Returns the value of attribute auth_request.
-
#auth_response ⇒ Object
Returns the value of attribute auth_response.
-
#ax_request ⇒ Object
Returns the value of attribute ax_request.
-
#ax_response ⇒ Object
Returns the value of attribute ax_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
Instance Method Summary collapse
-
#add_attributes(attributes = []) ⇒ Object
Add attributes you would like to read about user, to request.
-
#data ⇒ Object
Return data parsed to a Hash.
- #fetch_request(consumer) ⇒ Object
- #fetch_response(consumer, params, request, current_url) ⇒ Object
-
#initialize(options = {:test => false}) ⇒ MojeID
constructor
A new instance of MojeID.
-
#redirect_url(immediate = false) ⇒ Object
returns the url you have to redirect after you compose your request.
- #response_status ⇒ Object
- #store_request(consumer) ⇒ Object
- #store_response(consumer, params, request, current_url) ⇒ Object
-
#update_attributes(data = {}) ⇒ Object
Add attributes and they values which you would like to update user profile, to the request.
Constructor Details
#initialize(options = {:test => false}) ⇒ MojeID
Returns a new instance of MojeID.
16 17 18 19 |
# File 'lib/mojeid.rb', line 16 def initialize(={:test => false}) @test = [:test] OpenID::fetcher.ca_file = "#{File.dirname(__FILE__)}/cert/cznic-cacert-test.pem" if @test end |
Instance Attribute Details
#auth_request ⇒ Object
Returns the value of attribute auth_request.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def auth_request @auth_request end |
#auth_response ⇒ Object
Returns the value of attribute auth_response.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def auth_response @auth_response end |
#ax_request ⇒ Object
Returns the value of attribute ax_request.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def ax_request @ax_request end |
#ax_response ⇒ Object
Returns the value of attribute ax_response.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def ax_response @ax_response end |
#realm ⇒ Object
Returns the value of attribute realm.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def realm @realm end |
#return_to ⇒ Object
Returns the value of attribute return_to.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def return_to @return_to end |
#xrds_result ⇒ Object
Returns the value of attribute xrds_result.
23 24 25 |
# File 'lib/mojeid.rb', line 23 def xrds_result @xrds_result end |
Class Method Details
.get_consumer(session, store) ⇒ Object
29 30 31 |
# File 'lib/mojeid.rb', line 29 def self.get_consumer(session, store) OpenID::Consumer.new(session, store) end |
.get_openid_store(filestore_path) ⇒ Object
25 26 27 |
# File 'lib/mojeid.rb', line 25 def self.get_openid_store(filestore_path) OpenID::Store::Filesystem.new(filestore_path) end |
Instance Method Details
#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’)
61 62 63 64 65 66 |
# File 'lib/mojeid.rb', line 61 def add_attributes(attributes=[]) attributes.each do |attribute| attribute.is_a?(Array) ? add_attribute(attribute[0], attribute[1], attribute[2]) : add_attribute(attribute) end pack_attributes_into_request end |
#data ⇒ Object
Return data parsed to a Hash.
91 92 93 |
# File 'lib/mojeid.rb', line 91 def data @ax_response.data rescue {} end |
#fetch_request(consumer) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/mojeid.rb', line 33 def fetch_request(consumer) identifier = @test ? MOJEID_ENDPOINT_TEST : MOJEID_ENDPOINT process_discovery(consumer, identifier) @ax_request = OpenID::AX::FetchRequest.new pape_request = OpenID::PAPE::Request.new([OpenID::PAPE::AUTH_PHISHING_RESISTANT]) @auth_request.add_extension(pape_request) end |
#fetch_response(consumer, params, request, current_url) ⇒ Object
41 42 43 44 |
# File 'lib/mojeid.rb', line 41 def fetch_response(consumer, params, request, current_url) process_response_by_type(:get, consumer, params, request, current_url) @auth_response end |
#redirect_url(immediate = false) ⇒ Object
returns the url you have to redirect after you compose your request
76 77 78 |
# File 'lib/mojeid.rb', line 76 def redirect_url(immediate=false) @auth_request.redirect_url(realm, return_to, immediate) end |
#response_status ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/mojeid.rb', line 80 def response_status case @auth_response.status when OpenID::Consumer::FAILURE then return :failure when OpenID::Consumer::SUCCESS then return :success when OpenID::Consumer::SETUP_NEEDED then return :setup_needed when OpenID::Consumer::CANCEL then return :cancel else return :unknown end end |
#store_request(consumer) ⇒ Object
46 47 48 49 50 |
# File 'lib/mojeid.rb', line 46 def store_request(consumer) identifier = @test ? MOJEID_ENDPOINT_TEST : MOJEID_ENDPOINT process_discovery(consumer, identifier) @ax_request = OpenID::AX::StoreRequest.new end |
#store_response(consumer, params, request, current_url) ⇒ Object
52 53 54 55 |
# File 'lib/mojeid.rb', line 52 def store_response(consumer, params, request, current_url) process_response_by_type(:put, consumer, params, request, current_url) @auth_response end |
#update_attributes(data = {}) ⇒ Object
Add attributes and they values which you would like to update user profile, to the request. Accepts hash like { ‘axschema.org/namePerson’ => ‘my new great name’ }.
70 71 72 73 |
# File 'lib/mojeid.rb', line 70 def update_attributes(data={}) data.each { |attribute, value| set_attribute(attribute, value) } pack_attributes_into_request end |