Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@pixelygroup/keycloak-koa-connect
Advanced tools
This is a fork of https://github.com/xrian/keycloak-koa-connect
It is very convenient to integrate keycloak with express js by keycloak-nodejs-connect directly.
However, when we started a new project, we adopted koa as the server-side development framework and found that the conventional method of converting express middleware to koa middleware was not suitable for the keycloak-nodejs-connect library.
We will try to extend this documentation with every release. And cover some scenarios not mentioned in the original project.
$ npm i @pixelygroup/keycloak-koa-connect --save
Because the library is implemented with Typescript, if you directly import (require) in nodejs using ES syntax, you will get no value, thus you need to import it's .default attribute
In root folder create a keycloak.js
file with your configuration and init-keycloak.js
.
// keycloak.js
module.exports = {
'realm': '', // realm
'auth-server-url': '', // keycloak URL: http://127.0.0.1:8080/auth
'ssl-required': 'external',
'resource': '', // client ID
'bearer-only': true,
'credentials': {
'secret': 'if-enabled client-secret ,then-need-to-fill-in-here secret'
},
'use-resource-role-mappings': true,
'confidential-port': 0,
'realm-public-key': ''
}
// init-keycloak.js
const KeycloakConnect = require('@pixelygroup/keycloak-koa-connect').default
const bodyStore = require('@pixelygroup/keycloak-koa-connect/stores/body-store').default // If this option is used, it is legal to include the value of jwt in the body
const queryStore = require('@pixelygroup/keycloak-koa-connect/stores/query-store').default // If this option is used, it is also legal to pass a token at http://a.com?jwt=token
const Keycloak = require('./keycloak.js')
const keycloak = new KeycloakConnect({ store: [queryStore, bodyStore,]}, Keycloak)
module.exports = { keycloak }
Then in:
// index.js
const Koa = require('koa');
const app = new Koa();
const { keycloak } = require('./init-keycloak.js')
keycloak.middleware()
.map(item => {
app.use(item)
})
app.listen(3000);
// index.ts
import * as Koa from 'koa';
const app = new Koa();
const { keycloak } = require('./init-keycloak.js')
keycloak.middleware()
.map(item => {
app.use(item)
})
app.listen(3000)
If you define your routes in routes/index.js
, you need to import init-keycloack.js
there as well
// routes/index.js
const Router = require('koa-router')
const router = new Router()
const { keycloak } = require('../init-keycloak.js')
// ## To secure a resource with an application role for the current app:
router.get( '/special', keycloak.protect('special'), specialHandler )
// ## To secure a resource with an application role for a different app:
router.get( '/extra-special', keycloak.protect('other-app:special'), extraSpecialHandler )
// ## To secure a resource with a realm role:
router.get( '/admin', keycloak.protect( 'realm:admin' ), adminHandler )
FAQs
keycloak koa oauth jsonWebToken
We found that @pixelygroup/keycloak-koa-connect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.