2017 © Pedro Peláez
 

library nemid

Nemid package for php

image

nodes/nemid

Nemid package for php

  • Wednesday, July 18, 2018
  • by nodes
  • Repository
  • 2 Watchers
  • 19 Stars
  • 686 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 3 Open issues
  • 15 Versions
  • 17 % Grown

The README.md

Nem-id integration

A PHP Laravel library for using the Danish NemID for authenticating a user., (*1)

I'm sure it can be used easily without laravel also. Feel free to contribute to improvements, (*2)

image, (*3)

The library supports:

  • Preparing the parameters for the applet
  • Validate the returned signature and the certificate chain
  • Extract Name and PID
  • Matching PID to CPR SOAP webservice

This is a rewrite of an original library for an older version of the applet in java, (*4)

Original library can be found: https://code.google.com/p/nemid-php/, (*5)

To become a nemid partner please follow this Link, (*6)

You must then modify your composer.json file and run composer update to include the latest version of the package in your project., (*7)

"require": {
    "nodes/nemid": "^1.0"
}

Or you can run the composer require command from your terminal., (*8)

composer require nodes/nemid:^1.0

🔧 Laravel Setup

Setup service provider in config/app.php, (*9)

Nodes\Nemid\ServiceProvider::class

Publish config files, (*10)

php artisan vendor:publish --provider="Nodes\NemId\ServiceProvider"

If you want to overwrite any existing config files use the --force parameter, (*11)

php artisan vendor:publish --provider="Nodes\NemId\ServiceProvider" --force

Certificates

Make sure you have bcmath installed

sudo apt-get install php7.0-bcmath

If your p12 file is password protected and the password holds special characters, see this stack overflow post, (*12)

You got your p12 certificate now generate pem files, use following commands:, (*13)

publicCertificate:

openssl pkcs12 -in path.p12 -out certificate.pem -clcerts -nokeys, (*14)

NB: Remove the initial lines with Bag Attributes if present., (*15)

Only the -----BEGIN CERTIFICATE-----, the base64 encoded certificate and -----END CERTIFICATE----- are relevant., (*16)

privateKey & privateKeyPassword

openssl pkcs12 -in path.p12 -clcerts -out privateKey.pem, (*17)

Openssl will prompt you for a PEM pass phrase that will have to be set in your nemid.php configuration., (*18)

certifateAndPrivateKey & password (For PID/CPR match)

openssl pkcs12 -in path.p12 -out certificateAndPrivateKey.pem -chain, (*19)

The -nodes flag disables encryption and password protection of your certificates (it has nothing to do with Nodes)., (*20)

If left out Openssl will prompt you for a PEM pass phrase that will have to be set in your nemid.php configuration., (*21)

Now you have all the certificates needed -, (*22)

Copy the config file to htdocs and fill settings

Look in the config file for more help, (*23)

Login integration

In the inspiration folder an example of how you can setup the login flow can be found., (*24)

First prepare parameters to inject into the iframe. By creating a Login object., (*25)

$login = new Login(config('nodes.nemid'));, (*26)

Setup a html document with the iframe url, js with param data and a form for callbacks, (*27)

$login->getIFrameUrl();, (*28)

$login->getParams();, (*29)

The iframe will now submit the response to the form, (*30)

The submitted data is base64 encoded, besides that all errors comes as string while successfully logins are xml documents, (*31)

$response = base64_decode(\Input::get('response'));, (*32)

CertificationCheck::isXml($response), (*33)

Now validate the certificates and extract name and PID from it by initialize a CertificationCheck object, (*34)

$userCertificate = new CertificationCheck(config('nodes.nemid'));, (*35)

$certificate = $userCertificate->checkAndReturnCertificate($response);, (*36)

$certificate->getSubject()->getName();, (*37)

$certificate->getSubject()->getPid();, (*38)

PID/CPR match integration

Initialize a PidCprMatch object and call the function with pid and cpr params., (*39)

$pidCprMatch = new PidCprMatch(config('nodes.nemid'));, (*40)

$response = $pidCprMatch->pidCprRequest($pid, $cpr);, (*41)

A response object will be returned. The object has functions to to check match and possible errors, (*42)

$response->didMatch();, (*43)

Misc

  • The name Pseudonym or Pseudonym Pseudonym will be used for version 1 of nemid users, which have not set their name afterwards

Enjoy, (*44)

The Versions

18/07 2018

dev-master

9999999-dev http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

09/07 2018

1.0.7

1.0.7.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

20/06 2018

1.0.6

1.0.6.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

15/06 2018

1.0.5

1.0.5.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

15/06 2018

dev-analysis-8mKPp7

dev-analysis-8mKPp7 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

01/06 2017

dev-analysis-XWlDxE

dev-analysis-XWlDxE http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

01/06 2017

1.0.4

1.0.4.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

28/11 2016

1.0.3

1.0.3.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

1.0.2

1.0.2.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

1.0.1

1.0.1.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

1.0.0

1.0.0.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

dev-develop

dev-develop http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

dev-analysis-XVG1oB

dev-analysis-XVG1oB http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

10/11 2016

dev-analysis-8PBP3L

dev-analysis-8PBP3L http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id

08/11 2016

0.1.0

0.1.0.0 http://nodesagency.com

Nemid package for php

  Sources   Download

MIT

The Requires

 

by Casper Rasmussen

laravel php nodes nemid nem-id nem id