npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@island.is/login

v1.4.0

Published

Island.is Identification and Authentication Services (Login) for Node.js

Downloads

117

Readme

Note on fork:

This repository is a fork off of islandis-login. It's purpose is to address the issue with validation of certificates, see: https://github.com/mojoweb/islandis-login/pull/6.

To use this package, rather than the original, please replace your usage of islandis-login with @island.is/login

yarn add @island.is/login

islandis-login

Library to make life easier for you => Handle the Island.is Login.

To get started with Island.is Identification and Authentication Services (IAS) you'll need to apply: https://island.is/innskraningarthjonusta.

Once you've registered your company you can use this library to handle all the boring stuff for you.

How it works

In your application to Island.is IAS you'll be required to provide a callback URI to which a token will be POSTed on user login attempts (login attempts initiated via innskraning.island.is/?id=yourcompany.is).

The token the Ísland.is IAS returns to the service provider, for decoding by the service provider, is a digitally signed SAML 2 token encoded in Base 64 and UTF-8.

The SAML message returned by IAS will be digitally signed with a certificate issued by Auðkenni ehf. (Traustur bunadur). Furthermore, the message will have been transformed with xml-exc-c14n (Sh*t! XML... boring right?), prior to being digested with SHA256 and signed with a 2048-bit RSA key.

This library helps with validating and verifying the SAML token and the provided signature.

Usage

Use the constructor function to pass in the audienceUrl. The audienceUrl should be the hostname of the server the IAS request is sent to.

There is one public function provided => .verify(). Pass the token you receive from Island.is into this function and the library will make the magic happen.

IslandIsLogin validates the signature according to the technical specifications provided by the Ísland.is IAS.

Example usage

To install the module using npm:

$ npm i --save islandis-login

In Node.js, using the bundled Audkenni certificate:

const IslandISLogin = require("islandis-login");

const token =
    "[token you received to your callbackURI from Island.is login attempt]";

const loginIS = new IslandISLogin({
    audienceUrl: "api.vefur.is", // should be the hostname of the domain you registered with Island to which the request is sent. Used for validation purposes.
});

Or by passing a relative path to the Audkenni cert:

const IslandISLogin = require("islandis-login");

const token =
    "[token you received to your callbackURI from Island.is login attempt]";

const loginIS = new IslandISLogin({
    audienceUrl: "api.vefur.is",
    certPath: "cert/SomeOtherCert.pem",
});

Or pass the cert as string:

const IslandISLogin = require("islandis-login");

const token =
    "[token you received to your callbackURI from Island.is login attempt]";

const cert = `
-----BEGIN CERTIFICATE-----
MIIFfDCCA2SgAwIBAgICAyQwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVMx
...
-----END CERTIFICATE-----
`;

const loginIS = new IslandISLogin({
    audienceUrl: "api.vefur.is",
    cert,
});

Now verify the incoming token:

loginIS
    .verify(token)
    .then((user) => {
        // Token is valid, return user object
        console.log("User object ");
        console.log(user);
    })
    .catch((err) => {
        // Error verifying signature or token is invalid.
        console.log("Error verifying token");
        console.log(err);
    });

This is what the user object looks like:

{
    "user": {
        "kennitala": "2309932389",
        "mobile": "6210193",
        "fullname": "Patrekur Maron Magnússon",
        "ip": "69.153.265.128",
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.69 (KHTML, like Gecko) Chrome/69.0.3511.69 Safari/537.69",
        "destinationSSN": "5207170800",
        "authId": "",
        "authenticationMethod": "Íslykill"
    },
    "extra": {
        "destination": "https://api.vefur.is/innskraning",
        "audienceUrl": "api.vefur.is",
        "dates": { "notBefore": 1584812651351, "notOnOrAfter": 1584812981351 }
    }
}

A note on the fields provided:

The mobile value is not always present, it depends on if "Rafræn Skilríki" or "Íslykill" is used or not and other factors. The phonenumber is only delivered sometimes by Island.is so we can't count on it being present even if we force the user to use "Rafræn skilríki".

authenticationMethod value will be "Íslykill" if IceKey is used during login and "Rafræn símaskilríki" if e-Authentication using SIM card (Rafræn skilríki) was used.

You can force the user to use "Rafræn skilríki" by adding &qaa=4 to the login link e.g. https://innskraning.island.is/?id=advania.is&qaa=4.

authId can be provided by adding it to the original login link, e.g. https://innskraning.island.is/?id=advania.is&authId=11111111-1111-1111-1111-111111111111.

The authId will persist throughout the whole process,authId must be a valid GUID. This authId can e.g. be used to make sure that the login attempt was made by you.

For maximum security you should compare the value in the userAgent field to the value the user has client side to make sure that the request originated from the same user.

This is all covered in more detail in the implementation guide: https://island.is/innskraningarthjonusta/taeknilegar-upplysingar-taeknimenn.

Errors

List of potential errors that you might encounter calling .verify():

{
    "id": "INVALID-TOKEN-XML",
    "reason": "Invalid login token - cannot parse XML from Island.is."
}
{
    "id": "CERTIFICATE-INVALID",
    "reason": "[Certificate-Error-Object]"
}
{
    "id": "AUDIENCEURL-MISSING",
    "reason": "You must provide an 'audienceUrl' in the options when calling the constructor function."
}
{
    "id": "LOGIN-REQUEST-EXPIRED",
    "reason": "Login request has expired."
}
{
    "id": "AUDIENCEURL-NOT-MATCHING",
    "reason": "The AudienceUrl you provide must match data from Island.is."
}

Tests

See the fixtures example files.

You need a valid token returned from island.is that deserializes to a user object.

Projects utilizing the library

Myntkaup.is - Myntkaup is Iceland's best way to buy and sell Bitcoin. 🚀

[Your Project here] - Do you have a project that should be here? Just ping us!

Made with ☕ + 🍺 by

This library was made by the team at Mojo.is - You can hire us if you need top notch software development services.

Pull requests are welcomed and encouraged! 🙌

Contributers

The following individuals had a hand in making this library:

pmm1

atlipall

sebastienne

License

MIT