Comments (7)
I got the security to work for the documentation as follow:
in app.js
I configure swagger (in a module to simplify the code):
const swOptions = require('./swagger/swagger');
...
app.use()
...
.configure(swagger(swOptions))
The module is configured as follow:
module.exports = {
docsPath: '/docs',
uiIndex: path.join(__dirname, 'docs.html'),
info: {
title: 'Title of the Documentation',
description: 'Available endpoints'
},
securityDefinitions: {
bearer: {
type: "apiKey",
name: "authorization",
in: "header"
}
},
security: [
{
bearer: []
}
]
};
You need to set the 'securityDefinisions' and the security
array as far as I am using the default authorization of feathers I need to say that I will be sending a bearer
token. I define what is the bearer for the swagger UI to be able to generate the correct buttons (authorize one).
Then per service I can now set per route if this route needs authorization or not. So when you instantiate a service, you need:
// Initialize our service with any options it requires
app.use('/users', Object.assign(service(options), {
docs: def
}));
I am passing a definition which allows: custom description of the endpoint, to add params definition, examples etc.
For example if you want to limit a create route to authorized users:
module.exports = {
description: 'Users of the API (requires administrator role)',
find: {
},
get: {
},
create: {
security: [ {
bearer: []
}]
},
update: {
},
patch: {
},
remove: {
}
};
As far as security is an array you can pass it other security strategies and of course you can pass other objects for each method here is another example with method definition:
const params = require('./parameters');
module.exports = {
description: 'ERS Articles',
find: {
security: [ {
bearer: []
}],
description: 'Get articles relative to a node with the node',
summary: 'Returns the category (node) and its outgoing relatives with the association ers:article',parameters: [
params.qname,
params.limit,
params.skip
],
responses: {
"200": {
description: 'successful operation',
schema: {
type: "object",
example:
{
"data": [],
"category": [],
"_sys": {
"next": 'string',
"prev": 'string'
},
"limit": 'int',
"skip": 'int',
"total": "coming soon"
}
},
},
"404": {
description: 'not found',
schema: {
type: "string"
}
}
},
produces: ["application/json"]
}
};
I have externalised the params as I need to reuse the same one on other services.
I hope this configuration may help someone ;) as it did not work right away... some trial and error involved...
from feathers-swagger.
Not at the moment since hooks don't add any additional information in to the service. Another way might be to set it globally as done in the Sequelize example in https://github.com/feathersjs/feathers-swagger/blob/master/example/sequelize/app.js#L52-L63
from feathers-swagger.
I have now got it working with auth, through trial and error, like this:
In the {service}/index.js
file I have this section:
const _service = service(options);
_service.docs = {
securities: ['create', 'update', 'patch', 'remove']
};
app.use('/activity', _service);
but this seems redundant, as that information is given by setting the restrictToAuthenticated
hooks. Can those calls not 'inflect' where they come from and set this information automatically?
from feathers-swagger.
Example of authentication configuration was added to the repository.
from feathers-swagger.
I am not able to get that authorize button on top
I have added
securityDefinitions: { bearer: { type: "apiKey", name: "authorization", in: "header" } }, security: [ { bearer: [] } ]
above code.
from feathers-swagger.
See https://github.com/feathersjs-ecosystem/feathers-swagger/blob/master/example/swagger-v2/security.js for a working example.
You also have to define the securities for the services.
from feathers-swagger.
Thank you so much @Mairu
from feathers-swagger.
Related Issues (20)
- Remove SwaggerUI as direct dependency
- Feature: Recognize `multi: true` option of services
- Feature: Add support for multi create
- Feature: Add support for pagination
- Feature: Respect x-forwarded-prefix header
- Support for feathers v5 (Dove) HOT 9
- Error: Invalid service object passed for path `docs` HOT 3
- Feature: Support koa
- Feature: Support dove custom methods
- Feature: Create documentation for services with schemas of Feathersjs dove (v5)
- Documentation: Use docsify for documentation
- Bug: Can't access ID in path HOT 2
- Feature: Handle Type.Literal HOT 7
- Bug: Custom method definitions are effecting other methods HOT 1
- Feature: Documentation is only generated for methods provided via service options
- How can I get correct prefix with $ref in related models? HOT 2
- Bug: Documentation for Usage with SwaggerUI
- Static generation HOT 1
- Feature: ESM module HOT 7
- How to stop autogeneration of swagger-json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feathers-swagger.