-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
propagate configured AuthenticationStrategy to OpenApiSpec #3669
Comments
I found a simpler way without modifying all endpoints: constants.ts export namespace SECURITY_REQUIREMENT {
export const DEFAULT: SecurityRequirementObject[] = [
{
BearerAuth: [],
},
]
export const NONE: SecurityRequirementObject[] = [
]
} application.ts import { merge } from 'lodash';
// ...
constructor(options: ApplicationConfig = {}) {
// ...
const spec = this.getSync(RestBindings.API_SPEC);
merge(spec, {
security: SECURITY_REQUIREMENT.DEFAULT,
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('none')
@post('/users/login', {
security: SECURITY_REQUIREMENT.NONE,
responses: {
// ...
},
})
async userLogin(
... |
related to #2027 |
@derdeka I am working on #2027 :) And have similar code as mport { 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',
},
},
},
});
// ...
} on my local. Your suggestion seems reasonable to me. Will submit a draft PR in the near future and we can discuss further. |
see draft PR loopbackio/loopback4-example-shopping#267 |
Acceptance Criteria updated. |
Related to #2027 |
Closing as done (see #4693). |
Suggestion
The configured
AuthenticationStrategy
should propagate thesecurityschema
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
user.controller.ts
Please note, that
@authorize('jwt')
andsecurity
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-example
to leverage the new change.The text was updated successfully, but these errors were encountered: