Skip to content

Commit caec5c2

Browse files
authored
Merge pull request #24 from veracity/bugfix/memcache-issue
Bugfix/memcache issue
2 parents 80f7b84 + 70cd42a commit caec5c2

9 files changed

Lines changed: 108 additions & 94 deletions

File tree

.vscode/launch.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"console": "integratedTerminal",
2828
"internalConsoleOptions": "neverOpen",
2929
"port": 9229
30+
},
31+
{
32+
"type": "node",
33+
"request": "launch",
34+
"name": "Launch 101-JS-Auth",
35+
"program": "${workspaceFolder}\\samples\\101-JS-Auth\\start.js"
3036
}
3137
]
3238
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Veracity Authentication library for NodeJS
22
This library provides utilities that help with authentication against the Veracity Identity Provider.
33

4+
## Version 2.0 released
5+
The libray now store user data in the session object from [`express-session`](https://www.npmjs.com/package/express-session) (`req.session`). This change is done due to issues found with the version 1 of this package when running multiple node.exe processes on the same server.
6+
47
## Version 1.0 released
58
Version `1.0.0` is the first officially released and supported implementation of this library. The API has been changed from version `0.3.1-beta` and is not backwards compatible. This documentation as been revamped to describe the new library. See the code samples for detailed implementation instructions.
69

package-lock.json

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@veracity/node-auth",
3-
"version": "1.0.6",
3+
"version": "2.0.0",
44
"description": "A library for authenticating with Veracity and retrieving one or more access tokens for communicating with APIs.",
55
"scripts": {
66
"build:copy-files": "ts-node -T scripts/copy-files.ts",
@@ -39,8 +39,8 @@
3939
"request-promise-native": "^1.0.7"
4040
},
4141
"devDependencies": {
42-
"@types/express": "^4.17.1",
43-
"@types/express-session": "^1.15.14",
42+
"@types/express": "^4.17.2",
43+
"@types/express-session": "^1.15.16",
4444
"@types/jest": "^24.0.18",
4545
"@types/jsonwebtoken": "^8.3.4",
4646
"@types/lodash.omit": "^4.5.6",

samples/102-TS-Auth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"homepage": "https://developer.veracity.com",
2525
"devDependencies": {
26-
"@types/express": "^4.17.1",
27-
"@types/express-session": "^1.15.14",
26+
"@types/express": "^4.17.2",
27+
"@types/express-session": "^1.15.16",
2828
"ts-node": "^8.4.1",
2929
"typescript": "^3.6.3"
3030
},

src/api/VIDPWebAppStrategy.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import { VIDPOpenIDContext } from "../auth/VIDPOpenIDContext"
77
import { VERACITY_API_SCOPES, VERACITY_METADATA_ENDPOINT } from "../constants"
88
import { VIDPError, VIDPErrorSources, VIDPStrategyErrorCodes } from "../errors"
99
import { IVIDPTokenData, IVIDPWebAppStrategySettings } from "../interfaces"
10-
import { MemCache, memCacheInstance } from "../utils/MemCache"
10+
11+
/**
12+
* Express request object with key session that is express-session
13+
* or other, compatable session manager
14+
*/
15+
interface IRequestWithSession extends Request {
16+
session: any
17+
}
1118

1219
export type VIDPWebAppStrategyVerifier<TUser = any> = (
1320
data: IVIDPTokenData, req: Request, done: (err: any, user?: TUser, info?: any) => void) => void | Promise<void>
@@ -28,8 +35,7 @@ export class VIDPWebAppStrategy<TUser = any> implements Strategy {
2835

2936
public constructor(
3037
settings: IVIDPWebAppStrategySettings,
31-
private verifier: VIDPWebAppStrategyVerifier<TUser>,
32-
private memCache: MemCache = memCacheInstance
38+
private verifier: VIDPWebAppStrategyVerifier<TUser>
3339
) {
3440
this.settings = {
3541
apiScopes: [VERACITY_API_SCOPES.services],
@@ -67,14 +73,14 @@ export class VIDPWebAppStrategy<TUser = any> implements Strategy {
6773
}
6874
}
6975

70-
public async authenticate(req: Request, options?: any) {
76+
public async authenticate(req: IRequestWithSession, options?: any) {
7177
try {
7278
const metadata = await getVIDPMetadata(this.settings.metadataURL)
7379
const context = new VIDPOpenIDContext(req, {
7480
apiScopes: this.settings.apiScopes,
7581
authParams: this.authParams,
7682
accessTokenParams: this.accessTokenParams
77-
}, metadata, this.memCache)
83+
}, metadata)
7884

7985
const nextOp = await context.next()
8086
if (!nextOp) { // We are done with authentication

0 commit comments

Comments
 (0)