Giter VIP home page Giter VIP logo

io-spid-commons's Introduction

io-spid-commons

This repo contains:

  • a passport-strategy that implements SPID authentication
  • a method that configures an express endpoint to serve Service Provider metadata
  • a scheduled procedure that refreshes IDP metadata from the SPID registry
  • a redis cache provider to validate SAML InResponseTo field

You may use this package if you're going to implement a SPID Service Provider with a NodeJS express server.

Upgrading passport-saml

Beware that any changes to the method signatures of SAML.prototype.generateAuthorizeRequest and SAML.prototype.validatePostResponse must be reflected inside the CustomSamlClient class.

That's why the version of passport-saml in package.json is currently fixed at 1.3.5.

Store Additional data between login and acs steps

If you need to pass additional parameters from login request to acs callback, you can use built-in additional parameter management, by adding a new extraLoginRequestParamConfig block in configuration:

export type ExtraParamsT = t.TypeOf<typeof ExtraParams>;
export const ExtraParams = t.type({ test: t.string });

const appConfig: IApplicationConfig<ExtraParamsT> = {

  extraLoginRequestParamConfig: {
    codec: ExtraParams,
    requestMapper: (req) =>  
                    ExtraParams.decode({
                                        loginType: req.header("x-test-header"),
                                      })
  },

  assertionConsumerServicePath: "/acs",
  clientErrorRedirectionUrl: "/error",
  clientLoginRedirectionUrl: "/success",
  loginPath: "/login",
  metadataPath: "/metadata",
  sloPath: "/logout",
  spidLevelsWhitelist: ["SpidL2", "SpidL3"],
};

The acs callback will receive a second parameter, containing the information extracted during login step for the user:

const acs: AssertionConsumerServiceT<ExtraParamsT> = async (
  payload,
  extraParams
  // ^^^ 
  // ExtraParamsT | undefined
) => {
  logger.info("acs:%s%s", JSON.stringify(payload), JSON.stringify(extraParams));
  return ResponsePermanentRedirect({ href: "/success?acs" } as ValidUrl);
};

NOTE: If the mapper or the coded return a validation error, extraParams will be undefined. NOTE 2: It's better to define the codec with defaults and/or partial properties, to avoid undefined values during deploy phase (ie: Data stored before the deploy that cannot be decoded with new codec because of lack of required properties)

Local development

To run the project locally with the embedded example express application run the following commands:

yarn install
yarn build
docker-compose up --build

PS. If was present locally a previously cached version of io-spid-commons docker container and you get the error Unexpected token < on node_modules/xml-encription/lib/templates/encrypted-key.tpl.xml.js, is needed to clean all the old containers datas with docker system prune --all before running the project again.

io-spid-commons's People

Contributors

gunzip avatar shawill avatar burnedmarshal avatar pagopa-github-bot avatar aledore avatar arcogabbo avatar dependabot[bot] avatar balanza avatar alexgpeppe avatar labarilem avatar gquadrati avatar cloudify avatar raicastino avatar garma00 avatar bfabio avatar francescopersico avatar maudeg avatar mccalv avatar pp-ps avatar fabriziopapi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.