-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Suggestion
The configured AuthenticationStrategy should propagate the securityschema into the generated openapi spec. Currently each endpoint need several configuration options to make this possible.
Use Cases
With configured securityschemas the api explorer handles authentication information automatically and sends it to the lb4 server.
Examples
Currently I'm doing something like this:
application.ts
import { merge } from 'lodash';
// ...
constructor(options: ApplicationConfig = {}) {
// ...
const spec = this.getSync(RestBindings.API_SPEC);
merge(spec, {
components: {
securitySchemes: {
BasicAuth: {
type: 'http',
scheme: 'basic',
},
BearerAuth: {
type: 'http',
scheme: 'bearer',
},
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
name: 'X-API-Key',
},
},
},
});
// ...
}user.controller.ts
...
@authorize('jwt')
@get('/users', {
security: [{
BearerAuth: [],
}],
responses: {
[STATUS_CODE.OK]: {
content: { [CONTENT_TYPE.JSON]: { schema: { type: 'array', items: getModelSchemaRef(User) } } },
},
},
})
async userFind(
...Please note, that @authorize('jwt') and security is some kind of redundant and needs to be configured for each endpoint.
Acceptance criteria
-
Authentication strategy can contribute security schemas when it gets registered to an application. The security schema specs will be merged into
OpenAPISpec.components.schemas. Modify theregisterAuthenticationStrategy()method to handle the spec merge. -
Update
loopback4-shopping-exampleto leverage the new change.