mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	Fix keycloak sample code eslint issues
This commit is contained in:
		
							parent
							
								
									a317be66bf
								
							
						
					
					
						commit
						b4bb171d7b
					
				| @ -7,7 +7,7 @@ | |||||||
|  * keycloak should have access. You would probably limit access |  * keycloak should have access. You would probably limit access | ||||||
|  * to users you trust. |  * to users you trust. | ||||||
|  * |  * | ||||||
|  * The implementation assumes the following environement variables: |  * The implementation assumes the following environment variables: | ||||||
|  * |  * | ||||||
|  *  - AUTH_HOST |  *  - AUTH_HOST | ||||||
|  *  - AUTH_REALM |  *  - AUTH_REALM | ||||||
| @ -17,30 +17,26 @@ | |||||||
| // const  { User, AuthenticationRequired } = require('unleash-server');
 | // const  { User, AuthenticationRequired } = require('unleash-server');
 | ||||||
| const { User, AuthenticationRequired } = require('../lib/server-impl.js'); | const { User, AuthenticationRequired } = require('../lib/server-impl.js'); | ||||||
| 
 | 
 | ||||||
| 
 | const KeycloakStrategy = require('@exlinc/keycloak-passport'); | ||||||
| const KeycloakStrategy = require("@exlinc/keycloak-passport"); |  | ||||||
| const passport = require('passport'); | const passport = require('passport'); | ||||||
| 
 | 
 | ||||||
| const kcConfig = { | const host = `http://${process.env.AUTH_HOST}`; | ||||||
|     host: "http://" + process.env.AUTH_HOST, | const realm = process.env.AUTH_REALM; | ||||||
|     realm: process.env.AUTH_REALM, | const clientId = process.env.AUTH_CLIENT_ID; | ||||||
|     clientId: process.env.AUTH_CLIENT_ID, | const contextPath = process.env.CONTEXT_PATH; | ||||||
|     contextPath: '', // Use when  Unleash is hosted on an url like /unleash/
 |  | ||||||
|     clientSecret: "", |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| passport.use( | passport.use( | ||||||
|     "keycloak", |     'keycloak', | ||||||
|     new KeycloakStrategy( |     new KeycloakStrategy( | ||||||
|         { |         { | ||||||
|             host: kcConfig.host, |             host, | ||||||
|             realm: kcConfig.realm, |             realm, | ||||||
|             clientID: kcConfig.clientId, |             clientId, | ||||||
|             clientSecret: "We don't need that, but is required", |             clientSecret: "We don't need that, but is required", | ||||||
|             callbackURL: `${kcConfig.contextPath}/api/auth/callback`, |             callbackURL: `${contextPath}/api/auth/callback`, | ||||||
|             authorizationURL: `${kcConfig.host}/auth/realms/hamis/protocol/openid-connect/auth`, |             authorizationURL: `${host}/auth/realms/hamis/protocol/openid-connect/auth`, | ||||||
|             tokenURL: `${kcConfig.host}/auth/realms/hamis/protocol/openid-connect/token`, |             tokenURL: `${host}/auth/realms/hamis/protocol/openid-connect/token`, | ||||||
|             userInfoURL: `${kcConfig.host}/auth/realms/hamis/protocol/openid-connect/userinfo` |             userInfoURL: `${host}/auth/realms/hamis/protocol/openid-connect/userinfo`, | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         (accessToken, refreshToken, profile, done) => { |         (accessToken, refreshToken, profile, done) => { | ||||||
| @ -61,11 +57,16 @@ function enableKeycloakOauth(app) { | |||||||
| 
 | 
 | ||||||
|     passport.serializeUser((user, done) => done(null, user)); |     passport.serializeUser((user, done) => done(null, user)); | ||||||
|     passport.deserializeUser((user, done) => done(null, user)); |     passport.deserializeUser((user, done) => done(null, user)); | ||||||
|  | 
 | ||||||
|     app.get('/api/admin/login', passport.authenticate('keycloak')); |     app.get('/api/admin/login', passport.authenticate('keycloak')); | ||||||
| 
 | 
 | ||||||
|     app.get('/api/auth/callback', passport.authenticate('keycloak'), (req, res, next) => { |     app.get( | ||||||
|         res.redirect(`${kcConfig.contextPath}/`); |         '/api/auth/callback', | ||||||
|     }); |         passport.authenticate('keycloak'), | ||||||
|  |         (req, res) => { | ||||||
|  |             res.redirect(`${contextPath}/`); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     app.use('/api/admin/', (req, res, next) => { |     app.use('/api/admin/', (req, res, next) => { | ||||||
|         if (req.user) { |         if (req.user) { | ||||||
| @ -76,7 +77,7 @@ function enableKeycloakOauth(app) { | |||||||
|                 .status('401') |                 .status('401') | ||||||
|                 .json( |                 .json( | ||||||
|                     new AuthenticationRequired({ |                     new AuthenticationRequired({ | ||||||
|                         path: `${kcConfig.contextPath}/api/admin/login`, |                         path: `${contextPath}/api/admin/login`, | ||||||
|                         type: 'custom', |                         type: 'custom', | ||||||
|                         message: `You have to identify yourself in order to use Unleash. 
 |                         message: `You have to identify yourself in order to use Unleash. 
 | ||||||
|                         Click the button and follow the instructions.`,
 |                         Click the button and follow the instructions.`,
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user