auth_service
class auth_service implements auth_service_interface
| internal |
Authentication Service.
Handles JWT-based authentication (HS256/RS256) for SSO and support access.
Constants
| AUTH_JWT |
|
| AUTH_JWT_ALGORITHM_SHA |
|
| AUTH_JWT_ALGORITHM_RSA |
|
| ACTION_MIDDAG_LOGIN |
|
| PUBLIC_KEY |
|
Methods
Initializes the authentication process based on the token provided in the request.
Redirects the user to the home page or the requested URL safely.
Checks if the user is already logged in.
Generates a login URL with a JWT token based on the provided user data and expiration time.
Decodes a JWT token using RS256 algorithm (Public Key).
Handles RSA specific actions like support login.
Execute the support login action.
Authenticate a standard user via JWT.
Wrapper to handle JWT authentication logic.
Details
at line 73
static void
init()
Initializes the authentication process based on the token provided in the request.
at line 106
static void
redirect()
Redirects the user to the home page or the requested URL safely.
at line 130
static void
auth_check()
Checks if the user is already logged in.
at line 145
static moodle_url
generate_login_url(stdClass $user, int $expires = 120)
Generates a login URL with a JWT token based on the provided user data and expiration time.
at line 176
static protected stdClass
decrypt(string $value, string $key)
Decode a JWT token using HS256.
at line 188
static protected false|stdClass
decrypt_jwt_rsa(string $value)
Decodes a JWT token using RS256 algorithm (Public Key).
at line 205
static protected void
middag_rsa(mixed $data)
Handles RSA specific actions like support login.
at line 222
static protected void
action_middag_rsa_login()
Execute the support login action.
at line 244
static protected void
login_user(mixed $token)
Authenticate a standard user via JWT.
at line 296
static protected void
perform_safe_login(stdClass $user)
Performs the login process safely.
If running in a PHPUnit environment, it sets the global user without regenerating the session ID (which causes errors in CLI) and avoids the redirect (which kills the test). In production, it performs the standard complete_user_login and redirect.
at line 320
static protected void
auth_jwt(mixed $token)
Wrapper to handle JWT authentication logic.