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

balena-auth

v6.0.1

Published

Balena session authentication utilities

Downloads

29,166

Readme

balena-auth

npm version dependencies Build Status

Join our online chat at Gitter chat

Balena session authentication utilities

Role

The intention of this module is to provide low level access to how a balena authentication tokens are parsed and persisted.

THIS MODULE IS LOW LEVEL AND IS NOT MEANT TO BE USED BY END USERS DIRECTLY.

Unless you know what you're doing, use the balena SDK instead.

Installation

Install balena-auth by running:

$ npm install --save balena-auth

Documentation

The module returns a class that you use to get an instance of the auth module.

It accepts the following params:

| Param | Type | Description | | --- | --- | --- | | options | Object | options | | [options.dataDirectory] | string | false | the directory to use for storage in Node.js or false to create an isolated in memory instance. Values other than false are ignored in the browser. | | [options.tokenKey] | string | the key used to store the last token in the storage. token by default. |

Example

import BalenaAuth from 'balena-auth';
const auth = new BalenaAuth({
	dataDirectory: '/opt/cache/balena',
	tokenKey: 'token'
});

auth~setKey(key) ⇒ [ 'Promise' ].<void>

Kind: inner method of auth
Summary: Set the key
Access: public

| Param | Type | | --- | --- | | key | String |

Example

auth.setKey('...').then(() => { ... });

auth~hasKey() ⇒ [ 'Promise' ].<Boolean>

Kind: inner method of auth
Summary: Has a key
Returns: [ 'Promise' ].<Boolean> - has key
Access: public
Example

auth.hasKey().then((hasKey) => { ... });

auth~removeKey() ⇒ Promise

This promise is not rejected if there was no key at the time of removal.

Kind: inner method of auth
Summary: Remove the key
Access: public
Example

auth.removeKey();

auth~getType() ⇒ [ 'Promise' ].<TokenType>

Kind: inner method of auth
Summary: Gets the key type
Access: public
Example

auth.getType().then((type) => { ... });

auth~getKey() ⇒ [ 'Promise' ].<string>

Kind: inner method of auth
Summary: Gets the key
Access: public
Example

auth.getKey().then((key) => { ... });

auth~getAge() ⇒ [ 'Promise' ].<(number|undefined)>

Kind: inner method of auth
Summary: Gets the token age
Access: public
Example

auth.getAge().then((age) => { ... });

auth~isExpired() ⇒ [ 'Promise' ].<boolean>

Kind: inner method of auth
Summary: Checks if token is expired
Access: public
Example

auth.isExpired().then((expired) => { ... });

auth~isValid() ⇒ [ 'Promise' ].<boolean>

Kind: inner method of auth
Summary: Checks if token format is valid
Access: public
Example

auth.isValid().then((valid) => { ... });

auth~get2FAStatus() ⇒ [ 'Promise' ].<('not_required'|'pending'|'passed')>

Kind: inner method of auth
Summary: Gets whether passing a 2FA challenge is pending, passed or not required.
Access: public
Example

auth.get2FAStatus().then((get2FAStatus) => { ... });

auth~needs2FA() ⇒ [ 'Promise' ].<boolean>

Kind: inner method of auth
Summary: Checks whether passing 2FA is pending/needed
Access: public
Example

auth.needs2FA().then((needs2FA) => { ... });

Support

If you're having any problem, please raise an issue on GitHub and the balena team will be happy to help.

Tests

Run the test suite by doing:

$ npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that tslint runs without any warning:

$ npm run lint

License

The project is licensed under the Apache 2.0 license.