Class: OmniAuth::Strategies::NwbBis
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::NwbBis
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth-nwbbis.rb
Instance Method Summary collapse
- #auth_hash(user_info) ⇒ Object
- #bis_credentials ⇒ Object
- #callback_phase ⇒ Object
- #decrypt_logon_id(secdata) ⇒ Object
- #get_logon_status(logon_id) ⇒ Object
- #get_user_info(username) ⇒ Object
- #request_phase ⇒ Object
Instance Method Details
#auth_hash(user_info) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/omniauth-nwbbis.rb', line 55 def auth_hash(user_info) hash = AuthHash.new(:provider => name, :uid => user_info.fetch("a:EMail", nil)) puts user_info first_name = user_info.fetch("a:Vorname", "") last_name = user_info.fetch("a:Name", "") hash.info = { :name => "#{first_name} #{last_name}", :email => user_info.fetch("a:EMail", nil) } hash end |
#bis_credentials ⇒ Object
71 72 73 74 |
# File 'lib/omniauth-nwbbis.rb', line 71 def bis_credentials {:bis_user => .bis_user, :bis_password => .bis_password} end |
#callback_phase ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/omniauth-nwbbis.rb', line 26 def callback_phase secdata = request.params["secdata"] # Decrypt secdata logon_id = decrypt_logon_id(secdata) if logon_id.length >= 0 # Check Login Status logon_status = get_logon_status(logon_id) login_type = logon_status.fetch("a:LoginTyp", "Unbekannt") username = logon_status.fetch("a:Benutzername", nil) if login_type == "Login" and not username.nil? user_info = get_user_info(username) env['omniauth.auth'] = auth_hash(user_info) call_app! # Create Auth Hash else # Redirect to NWB Login response = Rack::Response.new response.redirect "#{.login_url}#{.callback_param}" response.finish end end end |
#decrypt_logon_id(secdata) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/omniauth-nwbbis.rb', line 76 def decrypt_logon_id(secdata) xml_body = BisXmlDecryptLogonId.new(secdata).result() envelope = BisXmlEnvelope.new(xml_body, bis_credentials).result() logon_id = "" res = BisClient.execute("http://tempuri.org/INWBService/EntschluesselLogonID", envelope) if res.success? MultiXml.parser = :ox xml = MultiXml.parse(res.body) if xml != nil logon_id = xml.fetch("s:Envelope", {}).fetch("s:Body", {}).fetch("EntschluesselLogonIDResponse", {}).fetch("EntschluesselLogonIDResult", "") end end logon_id end |
#get_logon_status(logon_id) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/omniauth-nwbbis.rb', line 96 def get_logon_status(logon_id) xml_body = BisXmlGetLogonStatus.new(logon_id).result() envelope = BisXmlEnvelope.new(xml_body, bis_credentials).result() logon_status = {} res = BisClient.execute("http://tempuri.org/INWBService/GibLogonStatus", envelope) if res.success? MultiXml.parser = :ox xml = MultiXml.parse(res.body) if xml != nil logon_status = xml.fetch("s:Envelope", {}).fetch("s:Body", {}).fetch("GibLogonStatusResponse", {}).fetch("GibLogonStatusResult", "") end end logon_status end |
#get_user_info(username) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/omniauth-nwbbis.rb', line 116 def get_user_info(username) xml_body = BisXmlGetUserInfo.new(username).result() envelope = BisXmlEnvelope.new(xml_body, bis_credentials).result() user_info = {} res = BisClient.execute("http://tempuri.org/INWBService/GibBenutzer", envelope) if res.success? MultiXml.parser = :ox xml = MultiXml.parse(res.body) if xml != nil user_info = xml.fetch("s:Envelope", {}).fetch("s:Body", {}).fetch("GibBenutzerResponse", {}).fetch("GibBenutzerResult", "") end end user_info end |
#request_phase ⇒ Object
20 21 22 23 24 |
# File 'lib/omniauth-nwbbis.rb', line 20 def request_phase response = Rack::Response.new response.redirect "#{.login_info_url}#{.callback_param}" response.finish end |