Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

authentication

Authentication for the client or server (or both) via WebAuthN.

Usage

Use the local OS authentication

import { Authentication } from '@environment-safe/authentication';

(()=>{
    const authenticator = new Authentication({
        passkey : 'native' // use native password store
    });
    try{
        const user = await authenticator.authenticate();
    }catch(ex){
        // login failures happen here
    }
})();

Provide your own authentication

import { Authentication } from '@environment-safe/authentication';

In the server:

try{
    const authenticator = new Authentication({
        host : 'my.passkey.host',
        port : '13009',
    }, {
        create : async (user)=>{
            // create a record
        },
        lookup : async (user)=>{
            // lookup a single record
        },
        remove : async (user)=>{
            // remove a single record
        },
        init : async ()=>{
            // initialize the DB
        },
    });
    await authenticator.serve((err, credentials)=>{
        // return false, an error or metadata associated with success
    });
}catch(ex){
    // server crash
}

In the client:

try{
    const authenticator = new Authentication({
        host : 'my.passkey.host',
        port : '13009',
    });
    const user = await authenticator.authenticate();
}catch(ex){
    // login failures happen here
}

For now the use cases are simple, but eventually it may be possible to run servers from clients.

Server side authentication is a work in progress and needs a little work.

This pattern should work across all environments, more granular control will require environment specific hooks.

Testing

Unfortunately this can't be fully automated to test on all browsers due to a missing feature in playwright, once this is done, we'll add support for webkit and firefox.

Run the es module tests to test the root modules

npm run import-test

to run the same test inside the browser:

npm run browser-test

to run the same test headless in chrome:

npm run headless-browser-test

to run the same test inside docker:

npm run container-test

Run the commonjs tests against the /dist commonjs source (generated with the build-commonjs target).

npm run require-test

Development

All work is done in the .mjs files and will be transpiled on commit to commonjs and tested.

If the above tests pass, then attempt a commit which will generate .d.ts files alongside the src files and commonjs classes in dist

About

Uniform Client/Server passkey interface

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages