Skip to content

Allow explicit configuration management #1

Description

@heyheyjp

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())

...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions