Currently, this module assumes it runs in an environment where the process.env.IDM_BASE_URL and process.env. JWT_PRIVATE_KEY variables are properly set.
There should be no hardcoded URLs or URL matching, not even as a default. We should require the application depending on this module to configure it with its own IDM URL and private JWT key either by passing a config object or by setting specified env variables.
Usage might then look something like:
import {
addUserToRequestFromJWT,
refreshUserFromIDMService,
extendJWTExpiration
} from '@learnersguild/idm-jwt-auth/lib/middlewares'
// ...
// ... set up your Express app ...
// ...
const authConfig = {
idmBaseUrl: appSpecificConfig.idmBaseUrl,
jwtPrivateKey: appSpecificConfig.jwtPrivateKey
}
app.use(addUserToRequestFromJWT(authConfig))
app.use(refreshUserFromIDMService(authConfig))
app.use(extendJWTExpiration(authConfig))
...
Where these functions, when invoked, return the actual middleware functions, now closures with references to the provided auth (if any).
To allow the module to default to process.env values, they'd just be invoked w/o any args:
...
app.use(addUserToRequestFromJWT())
app.use(refreshUserFromIDMService())
app.use(extendJWTExpiration())
...
Currently, this module assumes it runs in an environment where the
process.env.IDM_BASE_URLandprocess.env. JWT_PRIVATE_KEYvariables are properly set.There should be no hardcoded URLs or URL matching, not even as a default. We should require the application depending on this module to configure it with its own IDM URL and private JWT key either by passing a config object or by setting specified env variables.
Usage might then look something like:
Where these functions, when invoked, return the actual middleware functions, now closures with references to the provided auth (if any).
To allow the module to default to
process.envvalues, they'd just be invoked w/o any args: