File: authproc_php.md

package info (click to toggle)
simplesamlphp 1.19.7-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,920 kB
  • sloc: php: 202,044; javascript: 14,867; xml: 2,700; sh: 225; perl: 82; makefile: 70; python: 5
file content (58 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
`core:PHP`
==========

This is a filter which makes it possible to run arbitrary PHP code to modify the attributes or state of an user.

Parameters
----------

`class`
:   This is the name of the filter.
    It must be `'core:PHP'`.

`code`
:   The PHP code that should be run. This code will have two variables available: 

* `$attributes`.
    This is an associative array of attributes, and can be modified to add or remove attributes.
    
* `$state`.
    This is an associative array of request state. It can be modified to adjust data related to the authentication
    such as desired NameId, requested Attributes, authnContextRef and many more.

Examples
--------

Add the `mail` attribute based on the user's `uid` attribute:

    10 => array(
        'class' => 'core:PHP',
        'code' => '
            if (empty($attributes["uid"])) {
                throw new Exception("Missing uid attribute.");
            }

            $uid = $attributes["uid"][0];
            $mail = $uid . "@example.net";
            $attributes["mail"] = array($mail);
        ',
    ),


Create a random number variable:

    10 => array(
        'class' => 'core:PHP',
        'code' => '
            $attributes["random"] = array(
                (string)rand(),
            );
        ',
    ),

Force a specific NameIdFormat. Useful if an SP misbehaves and requests (or publishes) an incorrect NameId

    90 => array(
         'class' => 'core:PHP',
         'code' => '$state["saml:NameIDFormat"] = ["Format" => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient", "AllowCreate" => true];'
    ),