@@ -38,6 +38,50 @@ To use this CAS client in your own SQLPage application, you need to follow these
38
38
> `sqlpage.environment_variable(' CAS_ROOT_URL' )` with `(SELECT cas_root_url FROM cas_config)`
39
39
> in the `login.sql` and `redirect_handler.sql` files.
40
40
41
+ # # CAS v3 Authentication Flow, step by step
42
+
43
+ # ## Login
44
+ The client (usually a web browser) requests a resource from the application (client service).
45
+ The application redirects the client to the CAS server with a service URL (the URL to which CAS should return the user after authentication).
46
+
47
+ # ## CAS Server Authentication
48
+ The CAS server presents a login form.
49
+ The user submits their credentials (username and password).
50
+ Upon successful authentication, the CAS server redirects the user back to the application with a service ticket (ST) appended to the service URL.
51
+
52
+ # ## Service Ticket Validation
53
+ The application receives the service ticket and makes a back-channel request to the CAS server to validate the service ticket.
54
+ The CAS server responds with a success or failure. If successful, it also returns the user' s attributes (such as username, email, etc.).
55
+
56
+ ### User Session
57
+ Upon successful validation, the application creates a session for the user and grants access to the requested resource.
58
+
59
+ ### CAS v3 Pseudocode Implementation
60
+
61
+ ```plaintext
62
+ function authenticateUser(serviceUrl):
63
+ if userNotLoggedIn():
64
+ redirectToCasServer(serviceUrl)
65
+
66
+ function redirectToCasServer(serviceUrl):
67
+ casLoginUrl = "https://cas.example.com/login?service=" + urlEncode(serviceUrl)
68
+ redirect(casLoginUrl)
69
+
70
+ function casCallback(request):
71
+ serviceTicket = request.getParameter("ticket")
72
+ if serviceTicket is not None:
73
+ validationUrl = "https://cas.example.com/serviceValidate?ticket=" + serviceTicket + "&service=" + urlEncode(serviceUrl)
74
+ validationResponse = httpRequest(validationUrl)
75
+ if validateResponse(validationResponse):
76
+ userAttributes = extractAttributes(validationResponse)
77
+ createUserSession(userAttributes)
78
+ redirectToService(serviceUrl)
79
+ else:
80
+ authenticationFailed()
81
+ else:
82
+ error("Invalid service ticket.")
83
+ ```
84
+
41
85
## Notes
42
86
43
87
- This implementation uses the CAS 3.0 protocol. If your CAS server uses a different version of the protocol, you may need to modify the code (the ticket validation URL in redirect_handler.sql in particular).
0 commit comments