Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/v2.0 #27

Merged
merged 5 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Node.js 18.x, 20.x build

on:
push:
branches: [master, feat/v2.0]

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: testbuilds
cancel-in-progress: false

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm run test

- name: Get npm version
id: get-values
shell: bash
run: |
VERSION=$(node -p 't=require(`./package.json`).version')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Update Coverage Badge
uses: markusberg/coverage-badge-action@main
with:
version: ${{ steps.get-values.outputs.VERSION }}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
3 changes: 3 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*": "prettier --write --check"
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"trailingComma": "all"
"singleQuote": true
}
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [2.0.0] - 2024-02-18

- Add support for codepage 852 enabling eastern european characters in usernames
- Drop support for Node.js versions below 18
- Ecmascript only
- Migrate to vitest and node:test for testing

## [1.0.0] - 2019-07-19

### Added
Expand Down
84 changes: 43 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ltpa

[![travis build](https://img.shields.io/travis/markusberg/ltpa.svg)](https://travis-ci.org/markusberg/ltpa)
[![codecov coverage](https://img.shields.io/codecov/c/github/markusberg/ltpa/master.svg)](https://codecov.io/github/markusberg/ltpa)
[![node.js build](https://github.com/markusberg/ltpa/actions/workflows/master.yaml/badge.svg)](https://github.com/markusberg/ltpa/actions/workflows/master.yaml)
[![coverage](https://markusberg.github.io/ltpa/badges/coverage-2.0.0.svg)](https://github.com/markusberg/ltpa/actions)
[![version](https://img.shields.io/npm/v/ltpa.svg)](https://codecov.io/github/markusberg/ltpa)
[![license](https://img.shields.io/github/license/markusberg/ltpa.svg)](https://www.apache.org/licenses/LICENSE-2.0)

Expand All @@ -12,6 +12,8 @@ A small library for generating and validating ltpa tokens. Based on the

For developers integrating [Node.js](https://nodejs.org/) applications with the world of IBM Domino and/or Websphere.

Since version 2.0, this module is strictly ESmodule. If you require CommonJS, you can still use the 1.x versions.

## Retrieving the server secret

In IBM Domino, the server secret can be found in the
Expand Down Expand Up @@ -54,33 +56,35 @@ These examples are for [Express](https://expressjs.com/), but the functionality
Add the dependency and create a simple middleware:

```javascript
let ltpa = require("ltpa")
ltpa.setSecrets({
"example.com": "AAECAwQFBgcICQoLDA0ODxAREhM=",
import { getUserName, refresh, setSecrets } from 'ltpa'
import { NextFunction, Request, Response } from 'express'

setSecrets({
'example.com': 'AAECAwQFBgcICQoLDA0ODxAREhM=',
})

/***
/**
* Express Middleware
* Authenticate user by verifying the provided LtpaToken cookie
*/
function mwLtpaAuth(req, res, next) {
export function mwLtpaAuth(req: Request, res: Response, next: NextFunction) {
try {
let ltpaToken = ltpa.refresh(req.cookies.LtpaToken, "example.com")
let newCookie =
"LtpaToken=" + ltpaToken + "; Path=/; Domain=" + "example.com"
res.setHeader("Set-Cookie", newCookie)
const ltpaToken = refresh(req.cookies.LtpaToken, 'example.com')
const newCookie =
'LtpaToken=' + ltpaToken + '; Path=/; Domain=' + 'example.com'
res.setHeader('Set-Cookie', newCookie)
next()
} catch (err) {
console.log(err)
res.status(401).json({ message: "Not authorized for this resource" })
res.status(401).json({ message: 'Not authorized for this resource' })
}
}

/***
/**
* Express route
*/
router.get("/testAuth", mwLtpaAuth, function (req, res) {
res.send("user is logged in as " + ltpa.getUserName(req.cookies.LtpaToken))
router.get('/testAuth', mwLtpaAuth, (req: Request, res: Response) => {
res.send('user is logged in as ' + getUserName(req.cookies.LtpaToken))
})
```

Expand All @@ -89,34 +93,32 @@ router.get("/testAuth", mwLtpaAuth, function (req, res) {
If you need to access a backend Domino database using a specific user account,
you can generate an LtpaToken for that account using the `generate` method:

```javascript
let ltpa = require("ltpa")
let rp = require("request-promise")
```typescript
import { Request, Response } from 'express'
import { generate, generateUserNameBuf, setSecrets } from 'ltpa'

ltpa.setSecrets({
"example.com": "AAECAwQFBgcICQoLDA0ODxAREhM=",
setSecrets({
'example.com': 'AAECAwQFBgcICQoLDA0ODxAREhM=',
})

router.get("/myDominoView", function (req, res) {
let userNameBuf = ltpa.generateUserNameBuf("Sysadmin Account")
let backendToken = ltpa.generate(userNameBuf, "example.com")

let dominoRequest = {
uri: "https://domino.example.com/api/data/collections/name/myDominoView",
method: "GET",
strictSSL: true,
timeout: 30000,
headers: {
Cookie: "LtpaToken=" + backendToken,
},
}
router.get('/myDominoView', async (req: Request, res: Response) => {
const userNameBuf = generateUserNameBuf('CN=Sysadmin Account,O=Example Inc')
const backendToken = generate(userNameBuf, 'example.com')

rp(dominoRequest)
.then((response) => res.json(response))
.catch((err) => {
console.log(err)
res.status(500).send(err)
})
const url = new URL(
'/api/data/collections/name/myDominoView',
'https://domino.example.com/',
)
const headers = { Cookie: `LtpaToken=${backendToken}` }

try {
const response = await fetch(url, { headers })
const json = await response.json()
res.json(json)
} catch (err) {
console.error(err)
res.status(500).send(err)
}
})
```

Expand All @@ -138,9 +140,9 @@ $ npm run test:watch

When validating token expiration, the library will only respect its internal `validity` setting, and will disregard the expiration-date setting in provided tokens. To force the library to use the actual timestamp in the token, use the setStrictExpirationValidation() method. This behaviour might change in version 2.

### Character set
### Character sets

The module only works with usernames containing characters in the `ibm850` codepage (basically Latin-1). The username in the token _should be_ encoded in an IBM proprietary format called `LMBCS` (Lotus Multi-Byte Character Set) for which I have found no javascript implementation. However, `LMBCS` is backwards compatible with `ibm850` for all characters in that codepage so if your usernames don't contain characters outside of `ibm850`, then you're good to go.
The module only works with usernames containing characters in the `ibm850`, and `ibm852` codepages (this covers most of Europe). The username in the token is encoded in an old IBM/Lotus format called [`LMBCS` (Lotus Multi-Byte Character Set)](https://en.wikipedia.org/wiki/Lotus_Multi-Byte_Character_Set) for which I have found no javascript implementation.

### LTPA1 only

Expand Down
19 changes: 0 additions & 19 deletions jest.config.js

This file was deleted.

Loading