Skip to content

Commit

Permalink
Merge pull request #23 from veracity/feature/custom-refresh-token-mid…
Browse files Browse the repository at this point in the history
…dleware-type

Feature/custom refresh token middleware type
  • Loading branch information
rudfoss committed Oct 15, 2019
2 parents e596d79 + 19d197b commit 80f7b84
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ header|IVIDPJWTTokenHeader|
payload|TPayload|
signature|string|


### VIDPRequestErrorCodes


Expand Down Expand Up @@ -417,7 +418,7 @@ Property|Type|Description

Property|Type|Description
-|-|-
"malfomed_token"|"malfomed_token"|The token is malformed. It may not consist of three segments or may not be parseable by the `jsonwebptoken` library.
"malfomed_token"|"malfomed_token"|The token is malformed.<br>It may not consist of three segments or may not be parseable by the `jsonwebptoken` library.
"missing_header"|"missing_header"|The token is malformed. Its header is missing.
"missing_payload"|"missing_payload"|The token is malformed. Its payload is missing.
"missing_signature"|"missing_signature"|The token is malformed. Its signature
Expand All @@ -431,15 +432,15 @@ Property|Type|Description
Property|Type|Description
-|-|-
"missing_required_setting"|"missing_required_setting"|A required setting was missing. See description for more information.
"invalid_internal_state"|"invalid_internal_state"|The internal state of the system is not valid. This may occur when users peforms authentication too slowly or if an attacker is attempting a replay attack.
"invalid_internal_state"|"invalid_internal_state"|The internal state of the system is not valid. This may occur when users peforms authentication too slowly<br>or if an attacker is attempting a replay attack.
"verifier_error"|"verifier_error"|An error occured in the verifier function called once the authentication is completed.
"unknown_error"|"unknown_error"|This error code occurs if the system was unable to determine the reason for the error. Check the error details or innerError for more information.
"unknown_error"|"unknown_error"|This error code occurs if the system was unable to determine the reason for the error.<br>Check the error details or innerError for more information.

### VIDPRefreshTokenErrorCodes


Property|Type|Description
-|-|-
"cannot_resolve_token"|"cannot_resolve_token"|Token refresh middleware was unable to resolve the token using the provided resolver. See description for more details.
"cannot_resolve_token"|"cannot_resolve_token"|Token refresh middleware was unable to resolve the token using the provided resolver.<br>See description for more details.

<!-- /types -->
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@veracity/node-auth",
"version": "1.0.5",
"version": "1.0.6",
"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
11 changes: 5 additions & 6 deletions src/api/createRefreshTokenMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextFunction, Request } from "express"
import { Request } from "express"
import { getVIDPMetadata } from "../auth/getVIDPMetadata"
import { parseVIDPAccessToken } from "../auth/parseVIDPToken"
import { refreshVIDPAccessToken } from "../auth/refreshVIDPAccessToken"
Expand All @@ -8,7 +8,8 @@ import { VIDPError, VIDPErrorSources, VIDPRefreshTokenErrorCodes } from "../erro
import {
IVIDPAccessToken,
IVIDPAccessTokenData,
IVIDPWebAppStrategySettings
IVIDPWebAppStrategySettings,
RefreshTokenMiddlewareFunc
} from "../interfaces"

const resolveToken = (
Expand Down Expand Up @@ -37,10 +38,8 @@ export const createRefreshTokenMiddleware = (
options: IVIDPWebAppStrategySettings,
onTokenRefreshed: ((tokenData: IVIDPAccessTokenData, req: Request) => void | Promise<void>),
metadataURL: string
) => (
tokenResolverOrApiScope: (string | ((req: Request) => IVIDPAccessTokenData | Promise<IVIDPAccessTokenData>)),
refreshStrategy?: ((token: IVIDPAccessTokenData, req: Request) => boolean)
) => async (req: any, res: any, next: NextFunction) => {
): RefreshTokenMiddlewareFunc => (tokenResolverOrApiScope, refreshStrategy?) =>
async (req, res, next) => {
try {
const oldToken = await resolveToken(tokenResolverOrApiScope)(req)
if (!oldToken) {
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/RefreshTokenMiddlewareFunc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextFunction, Request } from "express"
import { IVIDPAccessTokenData } from "./IVIDPAccessToken"

export type RefreshTokenMiddlewareFunc = (
tokenResolverOrApiScope: (string | ((req: Request) => IVIDPAccessTokenData | Promise<IVIDPAccessTokenData>)),
refreshStrategy?: ((token: IVIDPAccessTokenData, req: Request) => boolean)
) => ((req: any, res: any, next: NextFunction) => Promise<void>)
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./IVIDPTokenData"
export * from "./IVIDPWebAppStrategySettings"
export * from "./IVIDPWTToken"
export * from "./VIDPErrorCode"
export * from "./RefreshTokenMiddlewareFunc"

0 comments on commit 80f7b84

Please sign in to comment.