swagger-api / swagger-api/swagger-ui

Authentication with keycloak.js

Open
#4,628 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: support
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Hi, i'm using keycloak to protect swagger document in my backend node app. and i want to use config.js to protect my keycloak configuration on object declared in config file.
"keycloak": {
"serverUrl": "url",
"realm": "realmName",
"clientId": "clientId"
},

Q&A (please complete the following information)
  • OS: ubuntu 18.04
  • Browser: chromium
  • Method of installation: npm
  • swagger-ui-dist version: 3.13.4
Content & configuration

in index.html file:
` <script>
var keycloak = Keycloak({
"realm": "realmName",
"url": "url",
"clientId": "clientId"
});
keycloak.init({ onLoad: 'login-required' }).success(() => {
// Build a system
const ui = SwaggerUIBundle({
url: "./swagger.json",
urls: [
{
url:"./swagger.json",
name: 'Docs1'
},
{
url: 'http://Docs2',
name: 'Docs2'
},
{
url: 'http://Docs3',
name: 'Docs3'
},
],
validatorUrl: null,
dom_id: '#swagger-ui',
requestInterceptor: (req) => {
if (req.loadSpec) {
keycloak.updateToken(5).success(function() {
req.headers = { 'authorization': 'Bearer ' + keycloak.token };

});

}
return req;

},
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",

})
window.ui = ui;

};
</script>
`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report only shows an index.html integration using keycloak.js and SwaggerUIBundle.requestInterceptor; start by clarifying whether the expected change is support for config.js or a request-interception issue. Reproduce with swagger-ui-dist 3.13.4 on Chromium and define done as a documented, working authentication flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
authentication
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.