All Projects → italia → spid-express

italia / spid-express

Licence: MIT License
Express middleware implementing SPID & Entra con CIE (Carta d'Identità Elettronica)

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to spid-express

Gitwar
🚀 Gitwar - Compete with Github
Stars: ✭ 44 (+62.96%)
Mutual labels:  expressjs, node-js
Node.js Bootstrap Starter Template
Node.js, Express, Pug, Twitter Bootstrap, Starter Template
Stars: ✭ 107 (+296.3%)
Mutual labels:  expressjs, node-js
Node Express Postgresql Server
Basic Node with Express + PostgreSQL Server
Stars: ✭ 74 (+174.07%)
Mutual labels:  expressjs, node-js
Practicalnode
Practical Node.js, 1st and 2nd Editions [Apress] 📓
Stars: ✭ 3,694 (+13581.48%)
Mutual labels:  expressjs, node-js
express-boilerplate
ExpressJS boilerplate with Socket.IO, Mongoose for scalable projects.
Stars: ✭ 83 (+207.41%)
Mutual labels:  expressjs, node-js
Serverless Express
Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB.
Stars: ✭ 4,265 (+15696.3%)
Mutual labels:  expressjs, node-js
Blueprint
solid framework for building APIs and backend services
Stars: ✭ 87 (+222.22%)
Mutual labels:  expressjs, node-js
react-full-stack-starter
🎈Full-stack React boilerplate using `create-react-app`, Babel, Node.js, and express
Stars: ✭ 22 (-18.52%)
Mutual labels:  expressjs, node-js
BotBlock.org
BotBlock - The List of Discord Bot Lists and Services
Stars: ✭ 29 (+7.41%)
Mutual labels:  expressjs, node-js
express-file-upload
Node.js Express Upload/Download File Rest APIs example with Multer
Stars: ✭ 64 (+137.04%)
Mutual labels:  expressjs, node-js
SEO-Dashboard
SEO dashboard from Search console Data using the Google Search API, Mysql database , NodeJS RESTAPI( ExpressJS) and reactJs Dashboard
Stars: ✭ 39 (+44.44%)
Mutual labels:  expressjs, node-js
timeoff-server
TimeOff is an application that allows companies' employees to set vacations before they begin taking their time off. Implemented in modern tech stack i.e. Node, Express, MongoDB.
Stars: ✭ 33 (+22.22%)
Mutual labels:  expressjs, node-js
roboserver
Control OpenComputers robots without writing any code!
Stars: ✭ 52 (+92.59%)
Mutual labels:  expressjs, node-js
Node Production
Take Your Node.js Project to The Production Environment (VPS/Dedicated Server).
Stars: ✭ 35 (+29.63%)
Mutual labels:  expressjs, node-js
node-express-mongo-passport-jwt-typescript
A Node.js back end web application with REST API, user JWT authentication and MongoDB data storage using TypeScript
Stars: ✭ 51 (+88.89%)
Mutual labels:  expressjs, node-js
Remote Code Execution Environment
Remote Code Execution system built with NodeJS and ReactJS. Have you ever wondered how code execution on competitive programming websites works? Code that runs code. Tried implementing that.
Stars: ✭ 84 (+211.11%)
Mutual labels:  expressjs, node-js
express-mvc-generator
Express' Model View Controller Application Generator.
Stars: ✭ 46 (+70.37%)
Mutual labels:  expressjs, node-js
Nodebestpractices
✅ The Node.js best practices list (December 2021)
Stars: ✭ 72,734 (+269285.19%)
Mutual labels:  expressjs, node-js
Backend-NodeJS-Golang-Interview QA
A collection of Node JS and Golang Backend interview questions please feel free to fork and contribute to this repository
Stars: ✭ 122 (+351.85%)
Mutual labels:  expressjs, node-js
spid-sp-test
SAML2 SPID/CIE Service Provider validation tool
Stars: ✭ 27 (+0%)
Mutual labels:  cie, spid

SPID

License GitHub issues Join the #spid-express channel Get invited SPID on forum.italia.it

spid-express

spid-express è un middleware per Express che implementa SPID e Entra con CIE (Carta d'identità Elettronica).

Puoi usare questo pacchetto per integrare SPID o CIE in un'applicazione Express.

Requisiti

  • Redis (per il salvataggio delle sessioni di autenticazione)
  • passport-saml 1.2.0 (versione esatta)

Uso

La funzione withSpid() abilita SPID su un'app Express esistente. È disponibile un esempio dell'uso in src/example.ts.

   withSpid({
     acs,                  // Funzione che riceve i dati al login dell'utente SPID
     app,                  // App Express
     appConfig,            // Endpoint dell'app
     doneCb,               // Callback (facoltativo)
     logout,               // Funzione da chiamare al logout SPID
     redisClient,          // Client Redis
     samlConfig,           // Configurazione del middleware
     serviceProviderConfig // Configurazione del Service Provider
   })

acs

La funzione acs() (Assertion Consumer Service) riceve i dati dell'utente SPID in userPayload se il login è avvenuto con successo. È definita come:

   type AssertionConsumerServiceT = (
     userPayload: unknown
   ) => Promise<
     | IResponseErrorInternal
     | IResponseErrorValidation
     | IResponsePermanentRedirect
     | IResponseErrorForbiddenNotAuthorized
   >

userPayload è un oggetto le cui chiavi sono gli attributi SPID richiesti in requiredAttributes.attributes (nell'oggetto serviceProviderConfig). Es:

  {
     name: 'Carla'
     familyName: 'Rossi'
     fiscalNumber: 'RSSCRL32R82Y766D',
     email: '[email protected]',
     ...
  }

app

L'istanza dell'app Express.

appConfig

L'oggetto appConfig configura gli endpoint dell'app. Es:

   const appConfig: IApplicationConfig = {
     assertionConsumerServicePath: "/acs",
     clientErrorRedirectionUrl: "/error",
     clientLoginRedirectionUrl: "/error",
     loginPath: "/login",
     metadataPath: "/metadata",
     sloPath: "/logout"
   };
  • assertionConsumerServicePath: L'endpoint al quale verranno POSTati i dati dell'utente dopo un login avvenuto con successo. È l'endpoint della funzione acs() e viene creato automaticamente.
  • clientErrorRedirectionUrl: URL al quale redirigere in caso di errore interno.
  • clientLoginRedirectionUrl: URL al quale redirigere in caso di login SPID fallito.
  • loginPath L'endpoint che inizia la sessione SPID. Generalmente è l'endpoint chiamato da spid-smart-button. Viene creato automaticamente.
  • metadataPath: L'endpoint del metadata. Viene creato automaticamente.
  • sloPath: L'endpoint per il logout SPID. La funzione collegata è quella passata in withSpid().

doneCb

La funzione chiamata dopo ogni risposta SAML (facoltativa).

logout

La funzione da chiamare al logout di SPID, definita come:

    type LogoutT = () => Promise<IResponsePermanentRedirect>

redisClient

L'istanza di RedisClient per connettersi a un server Redis.

samlConfig

L'oggetto samlConfig configura il middleware. Es:

   const samlConfig: SamlConfig = {
     RACComparison: "minimum",
     acceptedClockSkewMs: 0,
     attributeConsumingServiceIndex: "0",
     authnContext: "https://www.spid.gov.it/SpidL1",
     callbackUrl: "http://localhost:3000/acs",
     identifierFormat: "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
     issuer: "https://spid.agid.gov.it/cd",
     logoutCallbackUrl: "http://localhost:3000/slo",
     privateCert: fs.readFileSync("./certs/key.pem", "utf-8"),
     validateInResponseTo: true
   };
  • RACComparison: Impostare a "minimum".
  • acceptedClockSkewMs: Impostare a 0.
  • attributeConsumingServiceIndex: Impostare all'indice degli attributi richiesti definito nel metadata. Se l'app è l'unica applicazione SPID del Service Provider, impostare a "0".
  • authnContext: Livello SPID richiesto. "https://www.spid.gov.it/SpidL1", "https://www.spid.gov.it/SpidL2" o "https://www.spid.gov.it/SpidL3".
  • callbackUrl: L'URL completo di assertionConsumerServicePath
  • identifierFormat: Impostare a "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
  • issuer: URL del Service Provider.
  • logoutCallbackUrl: L'URL completo di sloPath
  • privateCert: Stringa con la chiave privata del Service Provider in formato PEM.
  • validateInResponseTo: Impostare a true.

serviceProviderConfig

L'oggetto serviceProviderConfig contiene i parametri del Service Provider. Es:

   const serviceProviderConfig: IServiceProviderConfig = {
     IDPMetadataUrl:
       "https://registry.spid.gov.it/metadata/idp/spid-entities-idps.xml",
     organization: {
       URL: "https://example.com",
       displayName: "Organization display name",
       name: "Organization name"
     },
     publicCert: fs.readFileSync("./certs/cert.pem", "utf-8"),
     requiredAttributes: {
       attributes: [
         "address",
         "email",
         "name",
         "familyName",
         "fiscalNumber",
         "mobilePhone"
       ],
       name: "Required attrs"
     },
     spidCieUrl: "https://preproduzione.idserver.servizicie.interno.gov.it/idp/shibboleth?Metadata",
     spidTestEnvUrl: "https://spid-testenv2:8088",
     spidValidatorUrl: "http://localhost:8080",
     strictResponseValidation: {
       "http://localhost:8080": true,
       "https://spid-testenv2:8088": true
     }
   };
  • IDPMetadataUrl: URL dei metadata degli IdP. Impostare a "https://registry.spid.gov.it/metadata/idp/spid-entities-idps.xml".
  • organization: Oggetto con i dati del Service Provider.
  • publicCert: Stringa con il certificato del Service Provider in formato PEM.
  • requiredAttributes: La lista, in attributes, degli attributi richiesti (identificativi in https://docs.italia.it/italia/spid/spid-regole-tecniche/it/stabile/attributi.html).
  • spidCieUrl: URL per l'accesso con Carta d'Identità elettronica ("Entra con CIE"). Impostare a "https://preproduzione.idserver.servizicie.interno.gov.it/idp/shibboleth?Metadata" per lo sviluppo.
  • spidTestEnvUrl: URL dell'istanza di spid-testenv2. Lasciare vuoto per disabilitare.
  • spidValidatorUrl: URL dell'istanza di spid-saml-check. Lasciare vuoto per disabilitare.
  • strictResponseValidation: Impostare come da esempio con gli URL di spid-testenv2 e spid-saml-check (se abilitati).

Avvio dell'applicazione di esempio integrata

L'applicazione di esempio (src/example.ts) può essere lanciata con:

docker-compose up

Dopo il messaggio [spid-express] info: samlCert expire in 12 months) l'app sarà pronta e in ascolto su http://localhost:3000.

Iniziare la sessione SPID con una GET su http://localhost:3000/login?entityID=xx_testenv2. xx_testenv2 è l'entityID di sviluppo che redirigerà il login a spid-testenv2.

Gli entityID che si possono usare in produzione sono "lepidaid", "infocertid", "sielteid", "namirialid", "timid", "arubaid", "posteid", "intesaid" e "spiditalia" (vedere src/config.ts).

Uso di Carta di Identità Elettronica (CIE)

Il middleware permette anche di interagire con gli IDP di collaudo e produzione di "Entra con CIE" dell'Istituto Poligrafico Zecca dello Stato. Non è presente al momento un ambiente di sviluppo.

Per poter utilizzare l'ambiente di collaudo è necessario federarsi inviando un modulo di richiesta come specificato nel manuale operativo CIE.

Una volta federati, è possibile utilizzare lo stesso endpoint utilizzato per SPID per l'accesso con CIE: l'entityID è "xx_servizicie" in produzione e "xx_servizicie_test" in collaudo.

Licenza

spid-express è rilasciato con licenza MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].