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