commit code to git
[raven/abandoned/asp.git] / Default.asp
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <!--#include file="Ucam_Webauth.vbs"-->
6 </head>
7 <%
8
9 Sub Main
10
11 ' Create 'Scripting.Dictionary' object
12 ' to hold the arguments we will supply
13 ' to the 'Ucam_Webauth' object.
14
15 Set args = CreateObject("Scripting.Dictionary")
16
17 ' Add the different arguments to the 'args'
18 ' associative array as name/value pairs.
19 ' Both name and value must be strings
20 ' so integers must be added as "x", eg. "60".
21
22 ' 'auth_service' is the WLS authentication server.
23 ' The following line gives the the demo Raven testing server:
24
25 ' args.Add "auth_service", "https://demo.raven.cam.ac.uk/auth/authenticate.html"
26
27 ' We're testing with our Dummy Raven WLS server so use that:
28 ' args.Add "auth_service", "http://www2.careers.cam.ac.uk:11812"
29
30 ' 'hostname' must be a domain name and perhaps a
31 ' port but nothing more.
32
33 args.Add "hostname", "localhost:81"
34
35 ' 'log_file' is the location of the logfile
36 ' which must be read/writable by the webserver.
37
38 args.Add "log_file", "C:/wamp/www/raven_asp/logs/vbscriptlog.txt"
39
40 ' 'key_dir' is the directory holding the
41 ' public key certificate.
42
43 args.Add "key_dir", "C:/wamp/www/raven_asp/certificates"
44
45 ' 'cookie_key' is the key used to generate
46 ' hash values of the authentication cookie.
47 ' Ideally it should be changed on a regular basis
48 ' but not during sessions.
49
50 args.Add "cookie_key", "Random string"
51
52 ' Create new instance of 'Ucam_Webauth'
53 ' and supply arguments.
54 ' We do not need to include 'Request' and 'Response'
55 ' variables (as in C# version), in order to get/set
56 ' cookies and server variables and perform redirects
57 ' as these variables are globally accessible to ASP class.
58
59 Set oUcam_Webauth = New Ucam_Webauth
60 Call oUcam_Webauth(args)
61
62
63 ' For the purposes of testing, we provide
64 ' a 'Logout' link that removes the local
65 ' authentication cookie and then displays
66 ' a link to easily logout the Raven WLS.
67 ' So we check to see if this 'Action=Logout'
68 ' link has been called and logout/display
69 ' link accordingly.
70
71 If (Request.ServerVariables("QUERY_STRING") = "Action=Logout") Then
72 oUcam_Webauth.ResetState()
73 Response.Write("Logged out of Raven (local)<br/>")
74 Response.Write("<a href='https://raven.cam.ac.uk/auth/logout.html'>Logout Raven (remote)</a><br/>" & _
75 "<a href='Default.asp'>Access Raven authenticated page</a>")
76 Exit Sub
77 End If
78
79 ' When you first access this page
80 ' the 'Authenticate' function will be called.
81 ' This will typically be called three times
82 ' in total to successfully authenticate the
83 ' user. In the first two iterations of
84 ' 'Authenticate', it will return
85 ' 'AUTHENTICATE_INCOMPLETE' while it
86 ' redirects the user's browser first to
87 ' the Raven WLS and then back to this page.
88 ' On the third iteration of 'Authenticate', it
89 ' will return 'AUTHENTICATE_COMPLETE_AUTHENTICATED'
90 ' or 'AUTHENTICATE_COMPLETE_NOT_AUTHENTICATED'
91 ' if the authentication process has fully
92 ' completed without error.
93
94 Select Case oUcam_Webauth.Authenticate()
95
96 Case oUcam_Webauth.AUTHENTICATE_INCOMPLETE
97
98 ' 'Authenticate' still redirecting pages
99 ' so don't do anything else.
100
101 Exit Sub
102
103 Case oUcam_Webauth.AUTHENTICATE_COMPLETE_AUTHENTICATED
104
105 ' Success so display the 'principal', ie. the user id.
106
107 Response.Write("SUCCESS. You are " & oUcam_Webauth.principal() & "<br/>")
108
109 ' Also display the 'ptags' parameter indicating
110 ' whether the user is 'current' or not.
111
112 Response.Write("Ptags = " & oUcam_Webauth.ptags() & "<br/>")
113
114 ' Display any 'GET variables' to check they
115 ' have carried through from the original
116 ' page request.
117
118 For Each item In Request.QueryString()
119 Response.Write item & "=" & Request.QueryString()(item) & "<br/>"
120 Next
121
122 ' Display a 'Logout' link to make it easy to
123 ' test authentication repeatedly.
124
125 Response.Write("<a href='Default.asp?Action=Logout'>Logout Raven (local)</a>")
126
127 Case Else
128
129 ' Either there was an error or a failed
130 ' authentication so print out the result either way.
131
132 Response.Write("FAIL - " & oUcam_Webauth.status() & ": " & oUcam_Webauth.msg())
133
134 ' Also log the error for debugging purposes.
135
136 oUcam_Webauth.write_log("FAIL - " & oUcam_Webauth.status() & ": " & oUcam_Webauth.msg())
137
138 End Select
139
140 End Sub
141
142 Call Main
143
144 %>
145 </html>