Debian Codegraph @

doc/sources/admin/hooks.rst

raw
1 Available plugin hooks
2 ======================
3
4 This page shows the list of hooks that you can use in your :doc:`custom plugins <plugincustom>`. Read the :doc:`plugincustom` page for full details on how to create and enable custom plugins.
5
6 .. contents::
7 :local:
8 :depth: 1
9
10 OpenID Connect Issuer hooks
11 ---------------------------
12
13 Discovery endpoint (/.well-known/openid-configuration)
14 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
16 oidcGenerateMetadata
17 ~~~~~~~~~~~~~~~~~~~~
18
19 .. versionadded:: 2.23.0
20
21 This hook is triggered when LemonLDAP::NG is building the OpenID Connect
22 discovery document (``/.well-known/openid-configuration``). It allows plugins
23 to add custom metadata fields to the discovery response.
24
25 The hook's parameter is a hash reference of the metadata document (which you can modify).
26
27 Sample code::
28
29 use constant hook => {
30 oidcGenerateMetadata => 'addMetadata',
31 };
32
33 sub addMetadata {
34 my ( $self, $req, $metadata ) = @_;
35 $metadata->{my_custom_endpoint} = 'https://example.com/custom';
36 push @{ $metadata->{grant_types_supported} }, 'my_custom_grant';
37 return PE_OK;
38 }
39
40 Authorization endpoint (/oauth2/authorize)
41 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42
43 oidcGotRequest
44 ~~~~~~~~~~~~~~
45
46 .. versionadded:: 2.0.10
47
48 This hook is triggered when LemonLDAP::NG received an authorization request on the ``/oauth2/authorize`` endpoint.
49
50 The hook's parameter is a hash containing the authorization request parameters.
51
52 Sample code::
53
54 use constant hook => {
55 oidcGotRequest => 'addScopeToRequest',
56 };
57
58 sub addScopeToRequest {
59 my ( $self, $req, $oidc_request ) = @_;
60 $oidc_request->{scope} = $oidc_request->{scope} . " my_hooked_scope";
61
62 return PE_OK;
63 }
64
65 oidcGenerateCode
66 ~~~~~~~~~~~~~~~~
67
68 .. versionadded:: 2.0.12
69
70 This hook is triggered when LemonLDAP::NG is about to generate an Authorization Code for a Relying Party.
71
72 The hook's parameters are:
73
74 * A hash of the parameters for the OIDC Authorize request, which you can modify
75 * the configuration key of the relying party which will receive the token
76 * A hash of the session keys for the (internal) Authorization Code session
77
78 Sample code::
79
80 use constant hook => {
81 oidcGenerateCode => 'modifyRedirectUri',
82 };
83
84 sub modifyRedirectUri {
85 my ( $self, $req, $oidc_request, $rp, $code_payload ) = @_;
86 my $original_uri = $oidc_request->{redirect_uri};
87 $oidc_request->{redirect_uri} = "$original_uri?hooked=1";
88 return PE_OK;
89 }
90
91 oidcResolveScope
92 ~~~~~~~~~~~~~~~~
93
94 .. versionadded:: 2.0.12
95
96 This hook is triggered when LemonLDAP::NG is resolving scopes (on authorization and token endpoints).
97
98 The hook's parameters are:
99
100 * An array ref of currently granted scopes, which you can modify
101 * The configuration key of the requested RP
102
103 Sample code::
104
105 use constant hook => {
106 oidcResolveScope => 'addHardcodedScope',
107 };
108
109 sub addHardcodedScope{
110 my ( $self, $req, $scopeList, $rp ) = @_;
111 push @{$scopeList}, "myscope";
112 return PE_OK;
113 }
114
115 oidcValidateRedirectUri
116 ~~~~~~~~~~~~~~~~~~~~~~~
117
118 .. versionadded:: 2.22.0
119
120 This hook lets you override the built-in URI validation logic
121
122 The hook's parameters are:
123
124 * The configuration key of the requested RP
125 * The redirect URI to validate
126 * The name of the endpoint that received the URI, such as
127
128 * ``authorization``
129 * ``end_session``
130
131 * A state object used to return the result of validation. Its subkeys are
132
133 * ``result``: boolean result of the URI validation
134
135 .. warning::
136
137 This hook must return ``PE_DONE`` in order to indicate that it performed
138 URI validation. The result of validation must be set in ``$state->{result}``.
139
140 Sample code ::
141
142 use URI;
143 use constant hook => { oidcValidateRedirectUri => 'allowLocalhost' };
144
145 sub allowLocalhost {
146 my ( $self, $req, $rp, $uri, $endpoint, $state ) = @_;
147
148 # If this RP is used by devs, allow all localhost urls
149 if ( $rp =~ /^dev-/ ) {
150
151 my $parsed_uri = URI->new($uri);
152 if ( $parsed_uri->host eq "localhost" ) {
153
154 # Force validation to succeed even if the URI
155 # is not declared in LemonLDAP::NG config
156 $state->{result} = 1;
157 return PE_DONE;
158 }
159 }
160
161 # Returning PE_OK means that we defer the decision to
162 # LemonLDAP::NG's built-in logic, which is to only allow
163 # explicitely declared URIs
164
165 return PE_OK;
166 }
167
168 oidcGenerateAuthorizationResponse
169 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170
171 .. versionadded:: 2.23.0
172
173 This hook is triggered when LemonLDAP::NG is about to send an authorization
174 response to a Relying Party (after the ``/oauth2/authorize`` endpoint completes).
175 It allows you to modify the response parameters before they are sent, for example
176 to implement JARM (JWT Secured Authorization Response Mode).
177
178 The hook's parameters are:
179
180 * A hash reference of the OIDC authorization request parameters
181 * The configuration key of the relying party
182 * A hash reference of response parameters that will be sent (can be modified)
183
184 The response_params hash may contain keys such as ``code``, ``state``,
185 ``id_token``, ``access_token``, ``token_type``, ``expires_in``, ``scope``,
186 and ``session_state``, depending on the flow used.
187
188 Sample code::
189
190 use constant hook => {
191 oidcGenerateAuthorizationResponse => 'wrapResponse',
192 };
193
194 sub wrapResponse {
195 my ( $self, $req, $oidc_request, $rp, $response_params ) = @_;
196
197 # Add a custom parameter to the response
198 $response_params->{custom_param} = "custom_value";
199
200 return PE_OK;
201 }
202
203
204 Token endpoint (/oauth2/token)
205 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
206
207 oidcGotClientCredentialsGrant
208 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209
210 .. versionadded:: 2.0.12
211
212 This hook is triggered when LemonLDAP::NG successfully authorized a :ref:`Client Credentials Grant <client-credentials-grant>`.
213
214 The hook's parameters are:
215
216 * A hash of the current session info
217 * the configuration key of the relying party which is being identified
218
219 .. versionchanged:: 2.21.0
220 You can use ``$info->{_scope}`` to update granted scopes in this hook
221
222 Sample code::
223
224 use constant hook => {
225 oidcGotClientCredentialsGrant => 'addSessionVariable',
226 };
227
228 sub addSessionVariable {
229 my ( $self, $req, $info, $rp ) = @_;
230 $info->{is_client_credentials} = 1;
231
232 return PE_OK;
233 }
234
235 oidcGotOnlineRefresh
236 ~~~~~~~~~~~~~~~~~~~~
237
238 .. versionadded:: 2.0.15
239
240 This hook is triggered when LemonLDAP::NG handles a Refresh Token grant for an
241 online session (user session still exists).
242
243 The hook's parameters are:
244
245 * the configuration key of the relying party which received the grant
246 * A hash of session data for the (internal) Refresh Token session
247 * A hash of the user's session data
248
249 .. versionchanged:: 2.23.0
250
251 The hook now supports ``PE_SENDRESPONSE`` to return a custom response.
252
253 Sample code::
254
255 use constant hook => {
256 oidcGotOnlineRefresh => 'logRefresh',
257 };
258
259 sub logRefresh {
260 my ( $self, $req, $rp, $refreshInfo, $sessionInfo ) = @_;
261 my $uid = $sessionInfo->{uid};
262 $self->userLogger->info("OIDC application $rp requested a new access token for $uid");
263 return PE_OK;
264 }
265
266 oidcGotOfflineRefresh
267 ~~~~~~~~~~~~~~~~~~~~~
268
269 .. versionadded:: 2.0.15
270
271 This hook is triggered when LemonLDAP::NG handles a Refresh Token grant for an
272 offline session (user session no longer exists).
273
274 The hook's parameters are:
275
276 * the configuration key of the relying party which received the grant
277 * A hash of session data for the (internal) Refresh Token session, which also
278 contains user attributes
279
280 .. versionchanged:: 2.23.0
281
282 The hook now supports ``PE_SENDRESPONSE`` to return a custom response.
283
284 Sample code::
285
286 use constant hook => {
287 oidcGotOfflineRefresh => 'logRefreshOffline',
288 };
289
290 sub logRefreshOffline {
291 my ( $self, $req, $rp, $refreshInfo ) = @_;
292 my $uid = $refreshInfo->{uid};
293 $self->userLogger->info("OIDC application $rp used offline access for $uid");
294 return PE_OK;
295 }
296
297 oidcGotTokenExchange
298 ~~~~~~~~~~~~~~~~~~~~
299
300 .. versionadded:: 2.0.16
301
302 This hook is triggered when LemonLDAP::NG handles an OAuth 2.0 Token Exchange request.
303
304 It allows you to implement your own custom Token Exchange flow.
305
306 You can look for parameters in ``$req``. If you find a combination of parameters that you support, set ``$req->response`` and return ``PE_SENDRESPONSE``. Else, return ``PE_OK`` to continue or ``PE_ERROR`` to fail.
307
308 Sample code::
309
310 use constant hook => { oidcGotTokenExchange => 'tokenExchange', };
311
312 sub tokenExchange {
313 my ( $self, $req, $rp ) = @_;
314 my $subject_token = $req->param('subject_token');
315 my $subject_token_type = $req->param('subject_token_type');
316
317 if ( #... ) {
318 $req->response(
319 $self->p->sendJSONresponse(
320 $req,
321 {
322 access_token => ...,
323 issued_token_type => ...,
324 token_type => ...,
325 }
326 )
327 );
328 return PE_SENDRESPONSE;
329 }
330 return PE_OK;
331 }
332
333 oidcGenerateTokenResponse
334 ~~~~~~~~~~~~~~~~~~~~~~~~~
335
336 .. versionadded:: 2.19.0
337
338 This hook is triggered when LemonLDAP::NG has generated id_token and access_token
339 and is about to send the token response.
340
341 .. versionchanged:: 2.23.0
342
343 This hook is now also called during refresh token grants.
344 A sixth parameter ``$grant_type`` (``'authorization_code'`` or ``'refresh_token'``)
345 is passed to distinguish between grant types.
346 The hook now supports ``PE_SENDRESPONSE`` to return a custom response.
347
348 The hook's parameters are:
349
350 * the configuration key of the relying party which will receive the tokens
351 * the prepared response before JSON encoding
352 * the OIDC session content (code session or refresh session)
353 * the user's session content
354 * the grant type string (``'authorization_code'`` or ``'refresh_token'``)
355
356 Sample code::
357
358 use constant hook => {
359 oidcGenerateTokenResponse => 'addTokenToResponse',
360 };
361
362 sub addTokenToResponse {
363 my ( $self, $req, $rp, $tokensResponse, $oidcSession, $userSession, $grant_type ) = @_;
364 $tokensResponse->{mySpecialToken} = 'randomValue';
365 return PE_OK;
366 }
367
368
369 oidcGotTokenRequest
370 ~~~~~~~~~~~~~~~~~~~
371
372 .. versionadded:: 2.23.0
373
374 This hook is triggered when the token endpoint receives a request, before
375 processing any grant type. It allows plugins to:
376
377 * Modify request parameters for any grant type (authorization_code, refresh_token, etc.)
378 * Log or audit all token requests
379 * Handle custom grant types such as CIBA or Device Authorization Grant (RFC 8628)
380
381 The hook's parameters are:
382
383 * the configuration key of the relying party
384 * the grant_type string that was received
385
386 The hook should return:
387
388 * ``PE_OK`` to continue normal processing (use this when modifying parameters or logging)
389 * ``PE_SENDRESPONSE`` to take over the response (plugin must set ``$req->response``)
390
391 Sample code::
392
393 use constant hook => {
394 oidcGotTokenRequest => 'handleTokenRequest',
395 };
396
397 sub handleTokenRequest {
398 my ( $self, $req, $rp, $grant_type ) = @_;
399
400 # Log all token requests
401 $self->logger->info("Token request for RP $rp with grant_type $grant_type");
402
403 # Handle custom grant types
404 if ( $grant_type eq 'urn:openid:params:grant-type:ciba' ) {
405 # Handle CIBA grant
406 $req->response( ... );
407 return PE_SENDRESPONSE;
408 }
409 elsif ( $grant_type eq 'urn:ietf:params:oauth:grant-type:device_code' ) {
410 # Handle Device Authorization Grant (RFC 8628)
411 $req->response( ... );
412 return PE_SENDRESPONSE;
413 }
414
415 # Continue with normal processing for standard grant types
416 return PE_OK;
417 }
418
419 Token generation
420 ^^^^^^^^^^^^^^^^
421
422 oidcGenerateAccessToken
423 ~~~~~~~~~~~~~~~~~~~~~~~
424
425 .. versionadded:: 2.0.12
426
427 This hook is triggered when LemonLDAP::NG is generating a JWT-formatted Access Token.
428
429 The hook's parameters are:
430
431 * A hash of the claims to be contained in the Access Token
432 * the configuration key of the relying party which will receive the token
433
434 .. versionadded:: 2.22.0
435
436 * A hash of additional JWT headers
437
438 Sample code::
439
440 use constant hook => {
441 oidcGenerateAccessToken => 'addClaimToAccessToken',
442 };
443
444 sub addClaimToAccessToken {
445 my ( $self, $req, $payload, $rp, $extra_headers ) = @_;
446 $payload->{"access_token_hook"} = 1;
447 return PE_OK;
448 }
449
450 oidcGenerateRefreshToken
451 ~~~~~~~~~~~~~~~~~~~~~~~~
452
453 .. versionadded:: 2.23.0
454
455 This hook is triggered when LemonLDAP::NG is generating a Refresh Token.
456 It allows plugins to add data to the refresh token session or reject the
457 token generation by returning a non-PE_OK value.
458
459 The hook's parameters are:
460
461 * A hash of the refresh token session data (which you can modify)
462 * the configuration key of the relying party
463 * a boolean indicating if this is an offline refresh token (true) or online (false)
464
465 Sample code::
466
467 use constant hook => {
468 oidcGenerateRefreshToken => 'addDataToRefreshToken',
469 };
470
471 sub addDataToRefreshToken {
472 my ( $self, $req, $refresh_info, $rp, $offline ) = @_;
473 if ( my $data = $req->data->{my_data} ) {
474 $refresh_info->{my_data} = $data;
475 }
476 # $offline is true for offline_access tokens
477 $refresh_info->{is_offline} = $offline ? 1 : 0;
478 return PE_OK;
479 }
480
481 oidcGenerateIDToken
482 ~~~~~~~~~~~~~~~~~~~
483
484 .. versionadded:: 2.0.10
485
486 This hook is triggered when LemonLDAP::NG is generating an ID Token.
487
488 The hook's parameters are:
489
490 * A hash of the claims to be contained in the ID Token
491 * the configuration key of the relying party which will receive the token
492
493 .. versionadded:: 2.22.0
494
495 * A hash of session information
496 * A hash of additional JWT headers
497
498 Sample code::
499
500 use constant hook => {
501 oidcGenerateIDToken => 'addClaimToIDToken',
502 };
503
504 sub addClaimToIDToken {
505 my ( $self, $req, $payload, $rp, $sessionInfo, $extra_headers ) = @_;
506 $payload->{"id_token_hook"} = 1;
507 return PE_OK;
508 }
509
510
511 UserInfo endpoint (/oauth2/userinfo)
512 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
513
514 oidcGenerateUserInfoResponse
515 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
516
517 .. versionadded:: 2.0.10
518
519 This hook is triggered when LemonLDAP::NG is about to send a UserInfo response to a relying party on the `/oauth2/userinfo` endpoint, or to compute a list of claims to be added in an ID or Access Token.
520
521 The hook's parameter is a hash containing all the claims that are about to be released.
522
523 .. versionchanged:: 2.0.15
524 Added the hash of current session data
525
526 Sample code::
527
528 use constant hook => {
529 oidcGenerateUserInfoResponse => 'addClaimToUserInfo',
530 };
531
532 sub addClaimToUserInfo {
533 my ( $self, $req, $userinfo, $rp, $session_data) = @_;
534 my $scope = $session_data->{_scope};
535 $userinfo->{"userinfo_hook"} = 1;
536 return PE_OK;
537 }
538
539
540 Introspection endpoint (/oauth2/introspect)
541 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
542
543 oidcGenerateIntrospectionResponse
544 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
545
546 .. versionadded:: 2.23.0
547
548 This hook is triggered when LemonLDAP::NG is building the token introspection response.
549 It allows plugins to modify the introspection response.
550
551 The hook's parameters are:
552
553 * A hash of the introspection response (which you can modify)
554 * the configuration key of the relying party making the introspection request
555 * A hash of the access token session data
556
557 Sample code::
558
559 use constant hook => {
560 oidcGenerateIntrospectionResponse => 'modifyIntrospection',
561 };
562
563 sub modifyIntrospection {
564 my ( $self, $req, $response, $rp, $token_data ) = @_;
565 if ( my $data = $token_data->{my_data} ) {
566 $response->{my_claim} = $data;
567 }
568 return PE_OK;
569 }
570
571
572 Dynamic Registration (/oauth2/register)
573 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574
575 oidcGotRegistrationRequest
576 ~~~~~~~~~~~~~~~~~~~~~~~~~~
577
578 .. versionadded:: 2.23.0
579
580 This hook is triggered when LemonLDAP::NG receives an OAuth2 dynamic client
581 registration request. It is only called when
582 ``oidcServiceAllowDynamicRegistration`` is enabled.
583
584 It allows custom plugins to filter or reject specific registration requests.
585
586 The hook receives the client registration metadata. To take over the response
587 (for example to reject the request), set ``$req->response`` and return
588 ``PE_SENDRESPONSE``.
589
590 The hook should return:
591
592 * ``PE_OK`` to allow the registration to proceed normally
593 * ``PE_SENDRESPONSE`` to return ``$req->response`` as the final response
594
595 Sample code::
596
597 use constant hook => {
598 oidcGotRegistrationRequest => 'filterRegistration',
599 };
600
601 sub filterRegistration {
602 my ( $self, $req, $client_metadata ) = @_;
603
604 # Only allow native apps with loopback URIs
605 my $redirect_uris = $client_metadata->{redirect_uris};
606 return PE_OK unless $redirect_uris && ref($redirect_uris) eq 'ARRAY';
607
608 foreach my $uri (@$redirect_uris) {
609 unless ( $uri =~
610 /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?(?:\/.*)?$/i )
611 {
612 $req->response(
613 $self->p->sendError( $req, 'invalid_request', 400 ) );
614 return PE_SENDRESPONSE;
615 }
616 }
617
618 return PE_OK;
619 }
620
621 oidcRegisterClient
622 ~~~~~~~~~~~~~~~~~~
623
624 .. versionadded:: 2.23.0
625
626 This hook is triggered just before saving the new RP configuration during
627 OAuth2 dynamic client registration.
628
629 It allows custom plugins to modify the new RP's configuration before it is
630 saved. The hook receives a ``$newRp`` hash reference with the same structure
631 as ``getOidcRpConfig``:
632
633 * ``confKey``: the configuration key for the new RP
634 * ``options``: hash of RP options (includes ``oidcRPMetaDataOptionsClientID``,
635 ``oidcRPMetaDataOptionsClientSecret``, etc.)
636 * ``attributes``: hash of exported variables
637 * ``macros``: hash of macros
638 * ``scopeRules``: hash of scope rules
639 * ``extraClaims``: hash of extra claims
640
641 The ``$client_metadata`` is also passed as a second parameter for read-only
642 context. Modifying it has no effect on the saved configuration.
643
644 Sample code::
645
646 use constant hook => {
647 oidcRegisterClient => 'supportPublicClients',
648 };
649
650 sub supportPublicClients {
651 my ( $self, $req, $newRp, $client_metadata ) = @_;
652 my $token_endpoint_auth_method =
653 $client_metadata->{token_endpoint_auth_method} || 'client_secret_basic';
654
655 # Support public clients (no secret)
656 if ( $token_endpoint_auth_method eq 'none' ) {
657 $self->logger->info("Registering public client");
658 delete $newRp->{options}->{oidcRPMetaDataOptionsClientSecret};
659 }
660
661 return PE_OK;
662 }
663
664
665 Dynamic RP configuration
666 ^^^^^^^^^^^^^^^^^^^^^^^^
667
668 getOidcRpConfig
669 ~~~~~~~~~~~~~~~
670
671 .. versionadded:: 2.17
672
673 This hook is triggered when processing a request for a Client ID that is not
674 registered as an OIDC RP.
675
676 You can use this hook to inject configuration on-demand. Update `$config` with
677 the RP configuration ::
678
679 use constant hook => {
680 getOidcRpConfig => 'getRpFromDB',
681 };
682
683 sub getRpFromDB {
684 my ( $self, $req, $client_id, $config ) = @_;
685
686 # Lookup $entityID in some DB
687
688 # Update the provided $config reference
689 %$config = (
690 confKey => # a unique configuration key
691 attributes => # hashref of attributes to return
692 options => # hashref of options
693 macros => # hashref of macros to compute
694 scopeRules => # hashref of scope rules
695 extraClaims => # hashref of additional scopes to consider
696 );
697
698 # If you don't set a TTL, the returned configuration is considered
699 # permanently valid. Even if nothing was returned.
700 $config->{ttl} = 3600;
701
702 # If you return a non-OK status, the hook will be called again
703 # on the next attempt to resolve the same entityID
704 return PE_OK;
705 }
706
707
708 OpenID Connect Authentication Hooks
709 -----------------------------------
710
711 oidcGenerateAuthenticationRequest
712 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
713
714 .. versionadded:: 2.0.15
715
716 This hook is triggered when LemonLDAP::NG is building the Authentication Request that will be sent to an OpenID Provider
717
718 The hook's parameters are:
719
720 * The configuration key of the OP
721 * A hash reference of request parameters that will be added to the OP's ``authorization_endpoint``.
722
723 Sample code::
724
725 use constant hook => {
726 oidcGenerateAuthenticationRequest => 'genAuthRequest',
727 };
728
729 sub genAuthRequest {
730 my ( $self, $req, $op, $authorize_request_params ) = @_;
731
732 $authorize_request_params->{my_param} = "my value";
733 return PE_OK;
734 }
735
736 .. versionchanged:: 2.23.0
737
738 Parameters specified in *Extra parameters for authorization code request* will
739 be exposed to this hook as well. If they start with a ``[`` or a ``{``, they
740 will be JSON-decoded automatically. LemonLDAP::NG will also automatically
741 JSON-encode and URL-encode them before adding them to the authorization
742 request.
743
744
745 oidcGenerateTokenRequest
746 ^^^^^^^^^^^^^^^^^^^^^^^^
747
748 .. versionadded:: 2.0.15
749
750 This hook is triggered when LemonLDAP::NG is building the Token Request from that will be sent to an OpenID Provider
751
752 The hook's parameters are:
753
754 * The configuration key of the OP
755 * A hash reference of request parameters that will be sent in the body of the request to the ``token_endpoint``.
756
757 Sample code::
758
759 use constant hook => {
760 oidcGenerateTokenRequest => 'genTokenRequest',
761 };
762
763 sub genTokenRequest {
764 my ( $self, $req, $op, $token_request_params) = @_;
765
766 $token_request_params->{my_param} = "my value";
767 return PE_OK;
768 }
769
770 oidcGotIDToken
771 ^^^^^^^^^^^^^^
772
773 .. versionadded:: 2.0.15
774
775 This hook is triggered after LemonLDAP::NG successfully received and decoded the ID Token from an external OpenID Provider
776
777 The hook's parameters are:
778
779 * The configuration key of the OP
780 * A hash reference of the decoded ID Token payload
781
782 Sample code::
783
784 use constant hook => {
785 oidcGotIDToken => 'modifyIDToken',
786 };
787
788 sub modifyIDToken {
789 my ( $self, $req, $op, $id_token_payload_hash ) = @_;
790
791 # do some post-processing on the `sub` claim
792 $id_token_payload_hash->{sub} = lc($id_token_payload_hash->{sub});
793 return PE_OK;
794 }
795
796 oidcGotUserInfo
797 ^^^^^^^^^^^^^^^
798
799 .. versionadded:: 2.0.15
800
801 This hook is triggered after LemonLDAP::NG successfully received the UserInfo response from an external OpenID Provider
802
803 The hook's parameters are:
804
805 * The configuration key of the OP
806 * A hash reference of decoded UserInfo payload
807
808 Sample code::
809
810 use constant hook => {
811 oidcGotUserInfo => 'modifyUserInfo',
812 };
813
814 sub modifyUserInfo {
815 my ( $self, $req, $op, $userinfo_content ) = @_;
816
817 # Custom attribute processing
818 $userinfo_content->{my_attribute} = 1;
819 return PE_OK;
820 }
821
822 oidcGotAuthenticationResponse
823 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
824
825 .. versionadded:: 2.23.0
826
827 This hook is triggered when LemonLDAP::NG receives an authentication response
828 (authorization callback) from an external OpenID Provider. It allows you to
829 process or modify the callback parameters before they are used, for example
830 to handle JARM (JWT Secured Authorization Response Mode) responses.
831
832 The hook's parameters are:
833
834 * A hash reference containing all callback parameters extracted from the request.
835 You can read or modify these values. Only the values in this hash will be used
836 by LemonLDAP::NG (not the raw request parameters).
837
838 Keys in the callback_params hash:
839
840 * ``state``: The state parameter (string or hashref, see below)
841 * ``code``: The authorization code
842 * ``error``: Error code if the authorization failed
843 * ``error_description``: Human-readable error description
844 * ``error_uri``: URI with more information about the error
845 * ``iss``: Issuer identifier (RFC 9207)
846
847 **State handling:**
848
849 * If ``state`` is a **scalar** (string), LemonLDAP::NG will call ``extractState``
850 to restore session data from the state token.
851 * If ``state`` is a **hashref**, LemonLDAP::NG assumes your hook has already
852 extracted the state and will use it directly. The hashref must contain:
853 ``_oidcOPCurrent``, ``_oidcNonce``, and optionally ``urldc``.
854
855 This allows hooks that decode wrapped responses (like JARM) to call
856 ``extractState`` themselves when they need the OP configuration to verify
857 the JWT signature.
858
859 Sample code::
860
861 use constant hook => {
862 oidcGotAuthenticationResponse => 'processCallback',
863 };
864
865 sub processCallback {
866 my ( $self, $req, $callback_params ) = @_;
867
868 # Check if this is a JARM response
869 my $jarm_response = $req->param('response');
870 if ($jarm_response) {
871 # Decode JWT (without verification to get claims first)
872 my $claims = decode_jwt($jarm_response);
873 my $state = $claims->{state};
874
875 # Extract state to get OP configuration (required before verification)
876 $self->extractState($req, $state);
877 my $op = $req->data->{_oidcOPCurrent};
878
879 # Now verify the JWT with OP's keys
880 # ... verification code ...
881
882 # Set callback params from JWT claims
883 # Keep state as scalar - LLNG will skip extractState since we already called it
884 # Alternatively, pass extracted state as hashref to skip extractState
885 $callback_params->{state} = {
886 _oidcOPCurrent => $req->data->{_oidcOPCurrent},
887 _oidcNonce => $req->data->{_oidcNonce},
888 urldc => $req->data->{_url},
889 };
890 $callback_params->{code} = $claims->{code};
891 }
892 return PE_OK;
893 }
894
895
896 SAML service hooks
897 ------------------
898
899 getSamlConfig
900 ^^^^^^^^^^^^^
901
902 .. versionadded:: 2.0.16
903
904 This hook is triggered when an entityID that is not registered in SAML
905 configuration (IDP or SP) is trying to communicate with LemonLDAP::NG
906
907 You can use this hook to inject configuration on-demand. Update `$config` with
908 the IDP or SP information::
909
910 use constant hook => {
911 getSamlConfig => 'getConfFromDB',
912 };
913
914 sub getConfFromDB {
915 my ( $self, $req, $entityID, $config ) = @_;
916
917 # Lookup $entityID in some DB
918
919 # Update the provided $config reference
920 %$config = (
921 sp_metadata => #XML metadata
922 sp_confKey => #configuration key
923 sp_attributes => #hashref of exported attributes
924 sp_options => #hashref of options
925 sp_macros => #hashref of macros
926
927 idp_metadata => #XML metadata
928 idp_attributes => #hashref of exported attributes
929 idp_options => #hashref of options
930 );
931
932 # If you don't set a TTL, the returned configuration is considered
933 # permanently valid. Even if nothing was returned.
934 $config->{ttl} = 3600;
935
936 # If you return a non-OK status, the hook will be called again
937 # on the next attempt to resolve the same entityID
938 return PE_OK;
939 }
940
941
942 SAML Issuer hooks
943 -----------------
944
945 samlGotAuthnRequest
946 ^^^^^^^^^^^^^^^^^^^
947
948 .. versionadded:: 2.0.10
949
950 This hook is triggered when LemonLDAP::NG has received a SAML login request
951
952 The hook's parameter is the Lasso::Login object
953
954 Sample code::
955
956 use constant hook => {
957 samlGotAuthnRequest => 'gotRequest',
958 };
959
960 sub gotRequest {
961 my ( $self, $req, $login ) = @_;
962
963 # Your code here
964 }
965
966 samlBuildAuthnResponse
967 ^^^^^^^^^^^^^^^^^^^^^^
968
969 .. versionadded:: 2.0.10
970
971 This hook is triggered when LemonLDAP::NG is about to build a response to the SAML login request
972
973 The hook's parameter is the Lasso::Login object
974
975 Sample code::
976
977 use constant hook => {
978 samlBuildAuthnResponse => 'buildResponse',
979 };
980
981 sub buildResponse {
982 my ( $self, $req, $login ) = @_;
983
984 # Your code here
985 }
986
987 samlGotLogoutRequest
988 ^^^^^^^^^^^^^^^^^^^^
989
990 .. versionadded:: 2.0.10
991
992 This hook is triggered when LemonLDAP::NG has received a SAML logout request
993
994 The hook's parameter is the Lasso::Logout object
995
996 Sample code::
997
998 use constant hook => {
999 samlGotLogoutRequest => 'gotLogout',
1000 };
1001
1002 sub gotLogout {
1003 my ( $self, $req, $logout ) = @_;
1004
1005 # Your code here
1006 }
1007
1008 samlGotLogoutResponse
1009 ^^^^^^^^^^^^^^^^^^^^^
1010
1011 .. versionadded:: 2.0.10
1012
1013 This hook is triggered when LemonLDAP::NG has received a SAML logout response
1014
1015 The hook's parameter is the Lasso::Logout object
1016
1017 Sample code::
1018
1019 use constant hook => {
1020 samlGotLogoutResponse => 'gotLogoutResponse',
1021 };
1022
1023 sub gotLogoutResponse {
1024 my ( $self, $req, $logout ) = @_;
1025
1026 # Your code here
1027 }
1028
1029 samlBuildLogoutResponse
1030 ^^^^^^^^^^^^^^^^^^^^^^^
1031
1032 .. versionadded:: 2.0.10
1033
1034 This hook is triggered when LemonLDAP::NG is about to generate a SAML logout response
1035
1036 The hook's parameter is the Lasso::Logout object
1037
1038 Sample code::
1039
1040 use constant hook => {
1041 samlBuildLogoutResponse => 'buildLogoutResponse',
1042 };
1043
1044 sub buildLogoutResponse {
1045 my ( $self, $req, $logout ) = @_;
1046
1047 # Your code here
1048 }
1049
1050 SAML Authentication hooks
1051 -------------------------
1052
1053 samlGenerateAuthnRequest
1054 ^^^^^^^^^^^^^^^^^^^^^^^^
1055
1056 .. versionadded:: 2.0.15
1057
1058 This hook is triggered when LemonLDAP::NG is building a SAML authentication request for an external IDP
1059
1060 The hook's parameters are:
1061
1062 * The configuration key of the IDP
1063 * The ``Lasso::Login`` object
1064
1065 Sample code::
1066
1067 use constant hook => {
1068 samlGenerateAuthnRequest => 'genRequest',
1069 };
1070
1071 sub genRequest {
1072 my ( $self, $req, $idp, $login ) = @_;
1073
1074 # Your code here
1075 }
1076
1077 samlGotAuthnResponse
1078 ^^^^^^^^^^^^^^^^^^^^
1079
1080 .. versionadded:: 2.0.15
1081
1082 This hook is triggered after LemonLDAP::NG successfully validated a SAML authentication response from an IDP
1083
1084 The hook's parameters are:
1085
1086 * The configuration key of the IDP
1087 * The ``Lasso::Login`` object
1088
1089 Sample code::
1090
1091 use constant hook => {
1092 samlGotAuthnResponse => 'gotResponse',
1093 };
1094
1095 sub gotResponse {
1096 my ( $self, $req, $idp, $login ) = @_;
1097
1098 # Your code here
1099 }
1100
1101
1102 CAS Issuer hooks
1103 -----------------
1104
1105 casGotRequest
1106 ^^^^^^^^^^^^^
1107
1108 .. versionadded:: 2.0.12
1109
1110 This hook is triggered when LemonLDAP::NG received an CAS authentication request on the `/cas/login` endpoint.
1111
1112 The hook's parameter is a hash containing the CAS request parameters.
1113
1114 Sample code::
1115
1116 use constant hook => {
1117 casGotRequest => 'filterService'
1118 };
1119
1120 sub filterService {
1121 my ( $self, $req, $cas_request ) = @_;
1122 if ( $cas_request->{service} eq "http://auth.sp.com/" ) {
1123 return PE_OK;
1124 }
1125 else {
1126 return 999;
1127 }
1128 }
1129
1130
1131 casGenerateServiceTicket
1132 ^^^^^^^^^^^^^^^^^^^^^^^^
1133
1134 .. versionadded:: 2.0.12
1135
1136 This hook is triggered when LemonLDAP::NG is about to generate a Service Ticket for a CAS application
1137
1138 The hook's parameters are:
1139
1140 * A hash of the parameters for the CAS request, which you can modify
1141 * the configuration key of the cas application which will receive the ticket
1142 * A hash of the session keys for the (internal) CAS session
1143
1144 Sample code::
1145
1146 use constant hook => {
1147 'casGenerateServiceTicket' => 'changeRedirectUrl',
1148 };
1149
1150 sub changeRedirectUrl {
1151 my ( $self, $req, $cas_request, $app, $Sinfos ) = @_;
1152 $cas_request->{service} .= "?hooked=1";
1153 return PE_OK;
1154 }
1155
1156
1157 casGenerateValidateResponse
1158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1159
1160 .. versionadded:: 2.0.12
1161
1162 This hook is triggered when LemonLDAP::NG is about to send a CAS response to an application on the `/cas/serviceValidate` endpoint.
1163
1164 The hook's parameters are:
1165
1166 * The username (CAS principal)
1167 * A hash of modifiable attributes to be sent
1168
1169 Sample code::
1170
1171 use constant hook => {
1172 casGenerateValidateResponse => 'addAttributes',
1173 };
1174
1175 sub addAttributes {
1176 my ( $self, $req, $username, $attributes ) = @_;
1177 $attributes->{hooked} = 1;
1178 return PE_OK;
1179 }
1180
1181
1182 DBI Authentication hooks
1183 ------------------------
1184
1185 dbiVerifyPassword
1186 ^^^^^^^^^^^^^^^^^
1187
1188 .. versionadded:: 2.20.0
1189
1190 This hook is triggered when LemonLDAP::NG is verifying a password hash
1191 :doc:`obtained from a database <authdbi>`. It will only run if *Dynamic
1192 hashing* is enabled
1193
1194 You can use this hook to implement a custom hashing scheme
1195
1196 The hook's parameters are:
1197
1198 * The password submitted by the user
1199 * The stored value, usually a hash, from the database
1200 * A state object used to return information to Auth::DBI. Its subkeys are
1201
1202 * ``result``: boolean result of the password verification
1203
1204 .. warning::
1205
1206 This hook must return ``PE_DONE`` in order to indicate that it performed
1207 password validation. The result of validation (good password or bad
1208 password) must be set in ``$state->{result}``.
1209
1210 Sample code::
1211
1212 use constant hook => { dbiVerifyPassword => 'verify_password', };
1213
1214 sub verify_password {
1215 my ( $self, $req, $submitted_password, $stored_hash, $state ) = @_;
1216
1217 # Check if the stored hash is understood by this plugin
1218 # TODO: adjust the regexp to match your custom scheme
1219 if ( $stored_hash =~ /^\$custom\$/ ) {
1220
1221 # TODO: use your own verification method here
1222 # my $is_correct_password = ...
1223
1224 $state->{result} = $is_correct_password;
1225
1226 # Return DONE to indicate that the verification was done.
1227 # Other plugins will not be called
1228 return PE_DONE;
1229 }
1230
1231 # Returning OK means that this plugin hasn't done anything
1232 # processing will continue to other plugins and default LemonLDAP::NG code
1233 return PE_OK;
1234 }
1235
1236
1237 dbiHashPassword
1238 ^^^^^^^^^^^^^^^
1239
1240 .. versionadded:: 2.20.0
1241
1242 This hook is triggered when LemonLDAP::NG is about to
1243 :doc:`set or change the user's password in a database <authdbi>`.
1244 It will only run if *Dynamic hashing* is enabled.
1245
1246 You can use this hook to implement a new algorithm that admins can
1247 configure as the *Hash scheme* for new passwords.
1248
1249 The hook's parameters are:
1250
1251 * The *Hash scheme* configured by the admin
1252 * The password to be stored
1253 * A state object used to return information to Password::DBI. Its subkeys are
1254
1255 * ``hashed_password``: the hashed value that will be stored in the database
1256
1257 .. warning::
1258
1259 This hook must return ``PE_DONE`` in order to indicate that it successfully
1260 hashed the password password validation.
1261
1262 Sample code::
1263
1264 use constant hook => { dbiHashPassword => 'hash_new_password', };
1265
1266 sub hash_new_password {
1267 my ( $self, $req, $scheme, $new_password, $result ) = @_;
1268
1269 # Check if the desired scheme is implemented by this plugin
1270 # TODO: replace by the name of your custom scheme
1271 if ( $scheme eq "MyCustomScheme" ) {
1272
1273 # TODO: use your own hashing method here
1274 # my $hashed_password = ...
1275
1276 $result->{hashed_password} = $hashed_password;
1277
1278 # Return DONE to indicate that the hashing was done.
1279 # Other plugins will not be called
1280 return PE_DONE;
1281 }
1282
1283 # Returning OK means that this plugin hasn't done anything
1284 # processing will continue to other plugins and default
1285 # LemonLDAP::NG code
1286 return PE_OK;
1287 }
1288
1289 Choice Authentication hooks
1290 ---------------------------
1291
1292 getAuthChoice
1293 ^^^^^^^^^^^^^
1294
1295 .. versionadded:: 2.20.0
1296
1297 This hook is triggered when LemonLDAP::NG selects an :doc:`authentication choice <authchoice>`.
1298
1299 It is only run if no built-in mechanism has succeeded, and lets you select an
1300 authentication choice from custom conditions instead of displaying a choice to
1301 the user.
1302
1303 The hook's only parameter is a context hash which you can modify. Its subkeys are
1304
1305 * ``choice``: set this key to the desired choice, or leave it empty to show the standard choice forms
1306
1307 Sample code::
1308
1309 use constant hook => { getAuthChoice => 'autoChoice', };
1310
1311 sub autoChoice {
1312 my ( $self, $req, $context ) = @_;
1313
1314 # Pick a default choice for all users on a certain IP
1315 if ( $req->address eq "1.2.3.4" ) {
1316 $context->{choice} = "1_DEMO";
1317 }
1318 return PE_OK;
1319 }
1320
1321
1322
1323 Password change hooks
1324 ---------------------
1325
1326
1327 .. _passwordBeforeChange:
1328
1329 passwordBeforeChange
1330 ^^^^^^^^^^^^^^^^^^^^
1331
1332 .. versionadded:: 2.0.12
1333
1334 This hook is triggered when LemonLDAP::NG is about to change or reset a user's password.
1335 Returning an error will cancel the password change operation.
1336 You can use this hook to implement :ref:`custom password policies <pluginppolicy>`.
1337
1338 The hook's parameters are:
1339
1340 * The main user identifier (warning: can be an email during the password reset flow)
1341 * The new password
1342 * The old password, if relevant
1343
1344 Sample code::
1345
1346 use constant hook => { passwordBeforeChange => 'blacklistPassword', };
1347
1348 sub blacklistPassword {
1349 my ( $self, $req, $_user, $password, $old ) = @_;
1350
1351 # Note: because $_user can be either a username or an email,
1352 # using an explicit attribute from sessionInfo is more reliable
1353 my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
1354
1355 if ( $password eq "12345" ) {
1356 $self->logger->error( "Password change refused for $user : "
1357 . "I've got the same combination on my luggage" );
1358 return PE_PP_INSUFFICIENT_PASSWORD_QUALITY;
1359 }
1360 return PE_OK;
1361 }
1362
1363
1364 passwordAfterChange
1365 ^^^^^^^^^^^^^^^^^^^
1366
1367 .. versionadded:: 2.0.12
1368
1369 This hook is triggered after LemonLDAP::NG has changed the user's password successfully in the underlying password database
1370
1371 The hook's parameters are:
1372
1373 * The main user identifier (warning: can be an email during the password reset flow)
1374 * The new password
1375 * The old password, if relevant
1376
1377 Sample code::
1378
1379 use constant hook => { passwordAfterChange => 'logPasswordChange', };
1380
1381 sub logPasswordChange {
1382 my ( $self, $req, $_user, $password, $old ) = @_;
1383 $old ||= "";
1384
1385 # Note: because $_user can be either a username or an email,
1386 # using an explicit attribute from sessionInfo is more reliable
1387 my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
1388
1389 # This is just an example, don't actually log a password!
1390 $self->userLogger->info(
1391 "Password changed for $user: $old -> $password");
1392 return PE_OK;
1393 }
1394
1395
1396 Second factor hooks
1397 -------------------
1398
1399 sfBeforeVerify
1400 ^^^^^^^^^^^^^^
1401
1402 .. versionadded:: 2.18
1403
1404 This hook is called immediately before LemonLDAP::NG calls the `verify` method
1405 of each second factor implementation in order to verify the code/response
1406 submitted by the user. You can use it to run additional checks.
1407
1408 The hook's parameters are:
1409
1410 * An instance of the 2F module in use
1411 * A hash of session information
1412
1413 Sample code::
1414
1415 use constant hook => { sfBeforeVerify => 'ipHasChanged', };
1416
1417 sub ipHasChanged {
1418 my ( $self, $req, $sfa, $session ) = @_;
1419 my $prefix = $sfa->prefix;
1420
1421 if ($req->address ne $session->{ipAddr}) {
1422 $self->logger->error("Error when validating $prefix: IP has changed");
1423 return PE_ERROR;
1424 }
1425
1426 return PE_OK;
1427 }
1428
1429 sfAfterVerify
1430 ^^^^^^^^^^^^^
1431
1432 .. versionadded:: 2.20
1433
1434 This hook is called after verifying a second factor, whether it was successful or not.
1435 You can use it to change the verification status depending on some condition.
1436
1437 The hook's parameters are:
1438
1439 * An instance of the 2F module in use
1440 * A hash of session information
1441 * A hash containing the verification result, which you can modify. Its subkeys are:
1442
1443 * ``authenticationLevel``: authentication level granted by the module
1444 * ``device``: if applicable, details of the 2FA device used (name, type, epoch, etc.)
1445 * ``result``: result code of this attempt
1446 * ``retries``: how many retries are left after this attempt
1447
1448 Sample code::
1449
1450 use constant hook => { sfAfterVerify => 'ipExceptions', };
1451
1452 sub ipExceptions {
1453 my ( $self, $req, $module, $session, $verify_result ) = @_;
1454
1455 my $status_of_verification = $verify_result->{result};
1456
1457 # Override authentication level for a particular IP
1458 if ( $status_of_verification == PE_OK and $req->address eq "127.0.0.1" )
1459 {
1460 $verify_result->{authenticationLevel} = 7;
1461 }
1462
1463 # This special IP has infinite retries
1464 if ( $status_of_verification != PE_OK
1465 and $req->address eq "127.0.0.2"
1466 and $verify_result->{retries} == 0 )
1467 {
1468 $self->logger->info("Allowing more retries to 127.0.0.2");
1469 $verify_result->{retries} = 1;
1470 }
1471 return PE_OK;
1472 }
1473
1474
1475 sfBeforeRetry
1476 ^^^^^^^^^^^^^
1477
1478 .. versionadded:: 2.19
1479
1480 If a second factor failed and should be retried, this hook is called just before retrying.
1481 You can use it to run additional checks before retrying, or reporting the
1482 failure to a third party.
1483
1484 The hook's parameters are:
1485
1486 * An instance of the 2F module in use
1487
1488 Sample code::
1489
1490 use constant hook => { sfBeforeRetry => 'allowedToRetry' };
1491
1492 sub allowedToRetry {
1493 my ( $self, $req, $module ) = @_;
1494
1495 # $module contains an instance of the 2FA module
1496 my $prefix = $module->prefix;
1497
1498 # Use $req->sessionInfo to get current session attributes
1499 my $uid = $req->sessionInfo->{uid};
1500
1501 if ( $uid eq "msmith" ) {
1502 $self->logger->error("User $uid not allowed to retry $prefix");
1503 return PE_ERROR;
1504 }
1505 return PE_OK;
1506 }
1507
1508 sfRegisterDevice
1509 ^^^^^^^^^^^^^^^^
1510
1511 .. versionadded:: 2.20
1512
1513 This hook is called immediately before registering a new second factor device
1514 into the user's persistent session.
1515 You can use it to abort the operation unless some condition is met, to modify
1516 the stored data, or to change the authentication level obtained immediately
1517 after registration.
1518
1519 The hook's parameters are:
1520
1521 * A hash of session information
1522 * A hash containing the second factor device data (type, name, timestamp, and implementation-specific fields)
1523 * A hash containing the current registration state, which you can modify to change the authentication level. Its subkeys are
1524
1525 * ``authenticationLevel``: authentication level granted by the module
1526 * ``module``: the object of the current 2fa module. Can be used to retrieve the type or prefix of 2fa
1527
1528 Sample code::
1529
1530 use constant hook => { sfRegisterDevice => 'specialDeviceNames' };
1531
1532 sub specialDeviceNames {
1533 my ( $self, $req, $info, $device, $registration_state ) = @_;
1534
1535 # If the device name given by the user contains the word "insecure",
1536 # downgrade the authentication level
1537 if ( $device->{name} =~ /insecure/i ) {
1538 $registration_state->{authenticationLevel} = 1;
1539 }
1540
1541 # If the device name contains the word "invalid",
1542 # abort registration
1543 if ( $device->{name} =~ /invalid/i ) {
1544 return PE_ERROR;
1545 }
1546
1547 return PE_OK;
1548 }
1549
1550
1551 sfDeleteDevice
1552 ^^^^^^^^^^^^^^
1553
1554 .. versionadded:: 2.23
1555
1556 This hook is called immediately before removing a second factor device
1557 into the user's persistent session.
1558 You can use it to abort the operation unless some condition is met.
1559
1560 The hook's parameters are:
1561
1562 * A hash of session information
1563 * The second factor type,
1564 * Device registration date
1565 * A hash containing the current registration state. Its subkeys are
1566
1567 * ``module``: the object of the current 2fa module. Can be used to retrieve the type or prefix of 2fa
1568
1569 Return value:
1570
1571 * ``PE_OK`` for success, any other value means an error. In case of error, you could specify a custom error message that would be returned by the SSO. To do so, just add an ``errorLabel`` key in ``$registration_state`` hash, with the value you want the SSO to return.
1572
1573 Sample code::
1574
1575 use constant hook => { sfDeleteDevice => 'checkUserBefore2fDelete' };
1576
1577 sub checkUserBefore2fDelete {
1578 my ( $self, $req, $info, $type, $epoch, $registration_state ) = @_;
1579
1580 my $module = $registration_state->{module};
1581 my $mail = $info->{mail};
1582
1583 # Don't allow 2nd factor removal if user have no mail
1584 unless ( $mail ) {
1585 $registration_state->{errorLabel} = "deleteHookError";
1586 return PE_ERROR;
1587 }
1588
1589 return PE_OK;
1590 }
1591
1592
1593 Generic hooks
1594 -------------
1595
1596 sendHtml
1597 ^^^^^^^^
1598
1599 .. versionadded:: 2.17
1600
1601 This hook is called whenever the LemonLDAP::NG portal is about to generate a page using its template engine
1602
1603 The hook's parameters are:
1604
1605 * A reference to the template name (it can be changed by plugins)
1606 * A reference to the hash of Lemonldap::NG::Common::sendHtml arguments, which
1607 includes template parameters and response code
1608
1609 Sample code::
1610
1611 use constant hook => { sendHtml => 'injectParam', };
1612
1613 sub injectParam {
1614 my ( $self, $req, $tpl, $args ) = @_;
1615
1616 # Add variable to the "menu.tpl" template
1617 if ( $$tpl eq "menu" ) {
1618 $args->{params}->{MY_PARAM} = "xx";
1619 }
1620 return PE_OK;
1621 }
1622
1623 unauthLogout
1624 ^^^^^^^^^^^^
1625
1626 .. versionadded:: 2.22.0
1627
1628 This hook is called just before any logout. It receive only one parameter, the
1629 `̀`$req`` object.