net-passport/net-passport

The single line sign on library for youuuu :)

1.1 2021-05-20 08:53 UTC

This package is not auto-updated.

Last update: 2025-05-16 04:31:47 UTC


README

net-passport is a all-strategy (Google, Facebook, etc...) server side authentication using Pure PHP in just a single line of code. You don't need any more boilerplate, repetitive configurations, strategies installations and more. Just use net-passport in your web application and manage your authenticated users! In addition, net-passport gives you a simple way for sign and verify messages using your NetPassport ID.

prerequisites

If you don't have one then go to NetPassport and create an account. After that, navigate to Console (on the left):

alt text

Then, click on "Generate key pair", scroll down and download the key-pair.

Alternatively, you could upload a private key you generated by yourself.

Installation

$ composer require net-passport/net-passport

Usage

use NetPassport\Signer;

Get your netPassportID in NetPassportHome on the top right:

alt text

you could click the "Copy" button to copy the id and paste it inside your code.

Load you private key

####load from disk

use Lcobucci\JWT\Signer\Key\LocalFileReference;
$privateKey = LocalFileReference::file(__DIR__ . '/path-to-my-key-stored-in-a-file.pem');

####Or load the keys from memory

 use Lcobucci\JWT\Signer\Key\InMemory;
$privateKey = InMemory::plainText('my-key-as-plaintext');

Server to server authentication

Sign data

// Initiate your message object
$message = [
  'netPassportID'   => "112233",
  'myData'          => "Hi there",
];

// Pass in two parameters that includes your object message (as mentioned above) and a private key or path to your private key
$signature = Signer::signObject($message, $privateKey);

Verify data

// Pass in two parameters that includes your original object message and the hashed signature of the message
$verifiedMessage = Signer::verify($message, $privateKey);

License

MIT