PHP developer in Milan

WordPress for businesses in Milan, delivered remotely by one developer.

PHP developer

My place in the WordPress community

  • I have had a wordpress.org account since 2006.
  • I contributed to WordPress core for versions 7.0 and 7.1.
  • I maintain 30 plugins on wordpress.org.
  • I organise and speak at WordCamps.
  • I have attended every WordCamp Europe from 2017 to 2026.
  • Local WordPress meetup: WordPress Meetup Milano

My WordPress.org profile

Glass towers around Piazza Gae Aulenti in Milan

Photo: DaveM93, CC BY-SA 3.0, Wikimedia Commons.

A web application in Milan that lets people log in with SPID has to follow a published technical specification, not a plugin default. This page is by Mariusz Szatkowski, who writes PHP from Gdynia, remotely and by email. It reads the AgID rules from the PHP side and flags the point where PHP sessions and the login flow collide.

#Which SPID rules apply to a PHP application?

The rules are the “SPID - Regole Tecniche” on Docs Italia, the AgID documentation site. They define how an Identity Provider, a Service Provider and an Attribute Authority integrate through SAML. The version on the stable branch is a consolidated one that includes the AgID notices (Avvisi) that amended the rules, up to Avviso n. 34.

A PHP web application that offers the login is the Service Provider. It sends a login request, receives a signed response and decides who the user is. Everything below concerns that role.

A second document on the same site, “SPID/CIE OpenID Connect”, describes SPID and CIE id on the OpenID Connect standards (OpenID Connect Core, the iGov profile and OpenID Connect Federation 1.0). I read its introduction only. Whether a given public service has to use the SAML route or the OpenID Connect route depends on the current AgID rules for that service, and that is a question for the service owner, not something I can settle from here. I am not a lawyer.

#What must the login request contain?

The login starts when the user picks an Identity Provider through the official “Entra con SPID” button. The Service Provider then builds an AuthnRequest. The rules list what it must carry:

ElementRule in the SPID rules
IDUnique, for example a UUID, or origin plus a timestamp with at least millisecond precision
VersionAlways 2.0
IssueInstantUTC, for example 2017-03-05T18:03:10.531Z
DestinationThe Location of the Identity Provider SingleSignOnService
ForceAuthnPresent when a level above SpidL1 is requested
AssertionConsumerServiceIndexPoints to an entry in the Service Provider metadata, with the HTTP-POST binding
IsPassiveMust not be present
IssuerThe entityID from the metadata, with Format entity and a NameQualifier
NameIDPolicyFormat transient
RequestedAuthnContextSpidL1, SpidL2 or SpidL3, with Comparison exact, minimum, better or maximum

With the HTTP-POST binding the request carries an XML signature made with RSA keys of at least 2048 bits and a SHA-256 or stronger digest. With HTTP-Redirect the signature travels in the SigAlg and Signature query parameters, with the same key and digest floor. The RelayState must reveal as little as possible about the requested resource, so an opaque value that maps to the target on the server fits better than a path.

In PHP the two request fields that are easy to get wrong are the ID and the timestamp:

$id = '_' . bin2hex(random_bytes(20));
$issued = (new DateTimeImmutable('now', new DateTimeZone('UTC')))
    ->format('Y-m-d\TH:i:s.v\Z');

The php.net manual describes random_bytes() as returning cryptographically secure random bytes, which is more than the rules ask for the ID, and the date format character v gives milliseconds on a DateTimeImmutable.

#What must the PHP application check in the response?

The Identity Provider returns a Response by the HTTP-POST binding only. The rules list what the Service Provider must verify before it uses the assertion:

  • the signatures on the Assertion and on the Response,
  • that Recipient in SubjectConfirmationData equals the AssertionConsumerServiceURL that received the message,
  • that NotOnOrAfter has not passed,
  • that InResponseTo refers to the ID of the AuthnRequest that was sent.

The Service Provider must also make sure assertions are not replayed. It keeps the set of request IDs for as long as the assertion is valid according to NotOnOrAfter, and it accepts only Responses that match an earlier, unexpired request. Unsolicited Responses are discarded. The assertion itself carries an AudienceRestriction with the entityID of the Service Provider, and the AuthnContextClassRef with the level that was actually used.

That last field matters. The rules say an Identity Provider may authenticate at a higher level than the request implies through Comparison, and that this must not make the request fail. An application that demands SpidL2 and tests for equality would reject a valid SpidL3 login. The check is on the level in the assertion, against the minimum the service needs.

$pending = $requests->takeOnce($inResponseTo); // your own store, one use only
if ($pending === null || $pending['expires_at'] <= time()) { reject(); }
if ($recipient !== $acsUrl)                    { reject(); }
if ($notOnOrAfter <= time())                   { reject(); }
if ($audience !== $spEntityId)                 { reject(); }

The signature checks themselves belong in a maintained SAML library rather than in hand-written XML handling. Two php.net facts apply wherever XML is parsed from a browser POST. The manual says external entity loading in libxml is disabled by default as of PHP 8.0, and that libxml_disable_entity_loader() is deprecated for that reason. And openssl_verify(), which verifies a raw signature such as the one in the Redirect binding, uses SHA-1 as its default algorithm, so the call needs OPENSSL_ALGO_SHA256 or stronger passed explicitly to meet the SHA-256 floor.

This is the trap that cannot be found in the SPID rules. It sits between them and PHP.

The Response comes back as a POST that the user’s browser sends from the Identity Provider’s page to the application. That is a cross-site POST. The php.net manual states, for session.cookie_samesite, that the values Lax and Strict mean the cookie is not sent cross-domain for POST requests, and that Lax still sends it for cross-domain GET requests. With a SameSite value on the session cookie, which the manual also lists as the default from PHP 8.6.0, the endpoint that receives the Response does not see the session that started the login.

A login flow that stores the pending request ID only in $_SESSION therefore fails, and it fails only on real browsers behind a real Identity Provider. The fix is to store each pending request on the server, keyed by its ID, with the RelayState, the minimum level and an expiry time. The receiving endpoint finds the request through InResponseTo, uses it once, and starts the authenticated session after the checks pass. That also fits the replay rule above, because the store of used IDs is the same table.

Two session habits follow. The session cookie stays on Lax or Strict, not None, because None would widen the cookie to every cross-site request. And once the assertion is verified, session_regenerate_id() gives the user a fresh ID, so a session ID set before login is not carried into the authenticated state. The php.net manual shows how to do the swap without losing the session.

#Which keys and certificates does SPID require?

The rules on metadata and algorithms set the floor for every Service Provider:

  • RSA keys of at least 2048 bits, and a SHA-256 digest, with SHA-512 also allowed.
  • A metadata file at the domain of the Service Provider under /metadata, fetched over the most recent TLS version available. The distribution to Identity Providers is done by AgID centrally, through the Registro.
  • A certificate that follows RFC 5280 with fixed subject fields. For a public Service Provider the organizationIdentifier takes the prefix PA:IT- followed by the IPA code of the body.
  • Public Service Providers, as identified in Avviso AgID n. 28/2020, may continue to use self-signed certificates.

One detail to treat with care: the example URL in the Redirect binding section of the rules shows a SigAlg ending in rsa-sha1, while the rule text asks for SHA-256 or stronger. A PHP implementation follows the text. That is my reading of an inconsistency in the document, and the Identity Provider test environment is the place to confirm it.

#What does Single Logout need on the PHP side?

The rules separate two sessions. An Identity Provider keeps an authentication session only after a SpidL1 login. For SpidL2 and SpidL3 no session is created, and every request repeats the authentication. The Service Provider has its own individual session for the service. Logout messages travel between the two, as a LogoutRequest and a LogoutResponse. The LogoutRequest must carry a unique ID, Version, IssueInstant and Destination, like the login request.

For the application this means that logging out of the PHP session is not the end of the SPID flow. Which logout mechanism a given service has to implement is set by the rules for that service, and the single sign-on and logout pages of the rules are the source.

#Checklist for a Milan PHP application with SPID login

  • Official SPID button, AuthnRequest with all required fields and no IsPassive.
  • Request ID from random_bytes(), IssueInstant in UTC with milliseconds.
  • Signed request, RSA of at least 2048 bits, SHA-256 or stronger.
  • Pending requests stored on the server by ID, never only in the PHP session.
  • Response checks: signatures, Recipient, NotOnOrAfter, InResponseTo, Audience.
  • One use per request ID, and discard unsolicited Responses.
  • Compare the level in AuthnContextClassRef against the minimum, not for equality.
  • session_regenerate_id() after a verified login.
  • Metadata under /metadata, reachable over current TLS.

#How a project runs

  1. You send the application address, the framework, the PHP version, the authentication level the service needs and your timeline. I reply by email in one working day.
  2. I write down the scope and my assumptions, including which part of the flow a library covers.
  3. I build on a staging copy, and you test the login against the test environment of the Identity Provider.
  4. Nothing goes live before you confirm the staging copy in writing.

Everything is remote. See the PHP developer page for the overall offer, and the maintenance plan page for WordPress sites. If you plan a SPID login, send the scope through the contact page. The first estimate in writing is free of charge.

Need this service: PHP developer in Milan?

Describe your project by e-mail. I reply within 24 hours.

Describe your project

Latest PHP developer articles

Dec 2, 2026

Laravel Rust: what does it mean for PHP apps?

On 1 December 2026 Taylor Otwell shipped the Laravel Rust beta, and Laravel Go followed a day later. What the framework contains, what the 18x benchmark really measures, what happens to Laravel PHP and WordPress, and when a rewrite makes sense.

Explore other WordPress services and knowledge base