0.6.0 • Published 1 year ago

httplease-asap v0.6.0

Weekly downloads
2,124
License
Apache-2.0
Repository
bitbucket
Last release
1 year ago

httplease-asap

This is an implementation of ASAP S2S Authentication as an httplease filter.

Usage guide

Install the library:

npm install --save httplease-asap

For more examples have a look at the test/integration directory.

Simple request

const httplease = require('httplease');
const httpleaseAsap = require('httplease-asap');


const jwtConfig = {
    privateKey: 'private key in pem format',
    issuer: 'an-issuer',
    keyId: 'the-keyid',
    audience: 'an-audience'
};

// this can be saved and reused as many times as you want
const httpClient = httplease.builder()
    .withBaseUrl('http://example.com/basePath')
    .withFilter(httpleaseAsap.createJwtAuthFilter(jwtConfig));


// make a request
httpClient
    .withPath('/post')
    .withMethodGet()
    .send();

jwtConfig from data URI

const httpleaseAsap = require('httplease-asap');

const dataUri = 'data:application/pkcs8;kid=an-issuer%2Fthe-keyid;base64,private key in base64 DER format';

const jwtConfig = Object.assign({
    issuer: 'an-issuer',
    audience: 'an-audience'
}, httpleaseAsap.parseDataUri(dataUri));

Just generate an auth header

The same jwtConfig format can be used to create a httplease filter or just a function which when called returns an authorization header.

const httpleaseAsap = require('httplease-asap');

const jwtConfig = {
    privateKey: 'private key in pem format',
    issuer: 'an-issuer',
    keyId: 'the-keyid',
    audience: 'an-audience',
    tokenExpiryMs: 10 * 60 * 1000, // Optional, max is 1 hour. This is how long the generated token stays valid.
    tokenMaxAgeMs: 9 * 60 * 1000 // Optional, must be less than tokenExpiryMs. How long to cache the token.
};

const authHeaderGenerator = httpleaseAsap.createAuthHeaderGenerator(jwtConfig);

const authHeader = authHeaderGenerator();

console.log(authHeader); // Bearer abcd1234

Additional claims

Just add them to your jwtConfig and use them with either createJwtAuthFilter or createAuthHeaderGenerator.

const jwtConfig = {
    // the usual stuff
    additionalClaims: {
        myCustomClaim: 'hello world'
    }
}

Development guide

Install dependencies

npm install

Useful commands

# Run all checks
npm test

# Run just the jasmine tests
npm run test:jasmine

# Run just the linter
npm run test:lint

Perform a release

npm version 99.98.97
npm publish
git push
git push --tags

Contributors

Pull requests, issues and comments welcome. For pull requests:

  • Add tests for new features and bug fixes
  • Follow the existing style
  • Separate unrelated changes into multiple pull requests

See the existing issues for things to start contributing.

For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change.

Atlassian requires contributors to sign a Contributor License Agreement, known as a CLA. This serves as a record stating that the contributor is entitled to contribute the code/documentation/translation to the project and is willing to have it used in distributions and derivative works (or is willing to transfer ownership).

License

Copyright (c) 2016 Atlassian and others. Apache 2.0 licensed, see LICENSE file.

0.6.0

1 year ago

0.5.0

2 years ago

0.4.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.3

4 years ago

0.3.2

5 years ago

0.3.1

7 years ago

0.3.1-beta1

7 years ago

0.3.0

7 years ago

0.3.0-beta2

7 years ago

0.3.0-beta1

7 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.2.0-beta2

8 years ago

0.2.0-beta1

8 years ago

0.1.0

8 years ago