Class: OmniAuth::Strategies::NwbBis

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth-nwbbis.rb

Instance Method Summary collapse

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()
    hash = AuthHash.new(:provider => name, :uid => .fetch("a:EMail", nil))

    puts 

    first_name = .fetch("a:Vorname", "")
    last_name = .fetch("a:Name", "")

    hash.info = {
        :name  => "#{first_name} #{last_name}",
        :email => .fetch("a:EMail", nil)
    }

    hash
end

#bis_credentialsObject



71
72
73
74
# File 'lib/omniauth-nwbbis.rb', line 71

def bis_credentials
    {:bis_user => options.bis_user,
     :bis_password => options.bis_password}
end

#callback_phaseObject



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)

         = logon_status.fetch("a:LoginTyp", "Unbekannt")
        username = logon_status.fetch("a:Benutzername", nil)

        if  == "Login" and not username.nil?
             = (username)

            env['omniauth.auth'] = auth_hash()
            call_app!

            # Create Auth Hash
        else
            # Redirect to NWB Login
            response = Rack::Response.new
            response.redirect "#{options.}#{options.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 (username)
    xml_body = BisXmlGetUserInfo.new(username).result()
    envelope = BisXmlEnvelope.new(xml_body, bis_credentials).result()

     = {} 

    res = BisClient.execute("http://tempuri.org/INWBService/GibBenutzer", envelope)

    if res.success?
        MultiXml.parser = :ox
        xml = MultiXml.parse(res.body)

        if xml != nil
             = xml.fetch("s:Envelope", {}).fetch("s:Body", {}).fetch("GibBenutzerResponse", {}).fetch("GibBenutzerResult", "")
        end
    end

     
end

#request_phaseObject



20
21
22
23
24
# File 'lib/omniauth-nwbbis.rb', line 20

def request_phase
    response = Rack::Response.new
    response.redirect "#{options.}#{options.callback_param}"
    response.finish
end