Skip to content

Commit

Permalink
Merge pull request #24 from veracity/bugfix/memcache-issue
Browse files Browse the repository at this point in the history
Bugfix/memcache issue
  • Loading branch information
SigurdMW committed Dec 3, 2019
2 parents 80f7b84 + 70cd42a commit caec5c2
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 94 deletions.
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"type": "node",
"request": "launch",
"name": "Launch 101-JS-Auth",
"program": "${workspaceFolder}\\samples\\101-JS-Auth\\start.js"
}
]
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Veracity Authentication library for NodeJS
This library provides utilities that help with authentication against the Veracity Identity Provider.

## Version 2.0 released
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.

## Version 1.0 released
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.

Expand Down
41 changes: 25 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@veracity/node-auth",
"version": "1.0.6",
"version": "2.0.0",
"description": "A library for authenticating with Veracity and retrieving one or more access tokens for communicating with APIs.",
"scripts": {
"build:copy-files": "ts-node -T scripts/copy-files.ts",
Expand Down Expand Up @@ -39,8 +39,8 @@
"request-promise-native": "^1.0.7"
},
"devDependencies": {
"@types/express": "^4.17.1",
"@types/express-session": "^1.15.14",
"@types/express": "^4.17.2",
"@types/express-session": "^1.15.16",
"@types/jest": "^24.0.18",
"@types/jsonwebtoken": "^8.3.4",
"@types/lodash.omit": "^4.5.6",
Expand Down
4 changes: 2 additions & 2 deletions samples/102-TS-Auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"homepage": "https://developer.veracity.com",
"devDependencies": {
"@types/express": "^4.17.1",
"@types/express-session": "^1.15.14",
"@types/express": "^4.17.2",
"@types/express-session": "^1.15.16",
"ts-node": "^8.4.1",
"typescript": "^3.6.3"
},
Expand Down
16 changes: 11 additions & 5 deletions src/api/VIDPWebAppStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { VIDPOpenIDContext } from "../auth/VIDPOpenIDContext"
import { VERACITY_API_SCOPES, VERACITY_METADATA_ENDPOINT } from "../constants"
import { VIDPError, VIDPErrorSources, VIDPStrategyErrorCodes } from "../errors"
import { IVIDPTokenData, IVIDPWebAppStrategySettings } from "../interfaces"
import { MemCache, memCacheInstance } from "../utils/MemCache"

/**
* Express request object with key session that is express-session
* or other, compatable session manager
*/
interface IRequestWithSession extends Request {
session: any
}

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

public constructor(
settings: IVIDPWebAppStrategySettings,
private verifier: VIDPWebAppStrategyVerifier<TUser>,
private memCache: MemCache = memCacheInstance
private verifier: VIDPWebAppStrategyVerifier<TUser>
) {
this.settings = {
apiScopes: [VERACITY_API_SCOPES.services],
Expand Down Expand Up @@ -67,14 +73,14 @@ export class VIDPWebAppStrategy<TUser = any> implements Strategy {
}
}

public async authenticate(req: Request, options?: any) {
public async authenticate(req: IRequestWithSession, options?: any) {
try {
const metadata = await getVIDPMetadata(this.settings.metadataURL)
const context = new VIDPOpenIDContext(req, {
apiScopes: this.settings.apiScopes,
authParams: this.authParams,
accessTokenParams: this.accessTokenParams
}, metadata, this.memCache)
}, metadata)

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

0 comments on commit caec5c2

Please sign in to comment.