-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(auto): check for jwt secret and mps credentials
BREAKING CHANGES: db schema changed to accept mps username
- Loading branch information
1 parent
b57c0ca
commit c9fa298
Showing
31 changed files
with
349 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/********************************************************************* | ||
* Copyright (c) Intel Corporation 2021 | ||
* SPDX-License-Identifier: Apache-2.0 | ||
**********************************************************************/ | ||
|
||
import { check } from 'express-validator' | ||
|
||
export const authValidator = (): any => { | ||
return [ | ||
check('username') | ||
.not() | ||
.isEmpty() | ||
.withMessage('User name is required'), | ||
check('password') | ||
.not() | ||
.isEmpty() | ||
.withMessage('Password is required') | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import { validationResult } from 'express-validator' | ||
import jws from 'jws' | ||
export async function login (req, res): Promise<void> { | ||
const errors = validationResult(req) | ||
if (!errors.isEmpty()) { | ||
res.status(400).json({ errors: errors.array() }) | ||
return | ||
} | ||
const username = req.body.username | ||
const password = req.body.password | ||
if (username && password) { | ||
// todo: implement a more advanced authentication system and RBAC | ||
if (username === req.mpsService.config.web_admin_user && password === req.mpsService.config.web_admin_password) { | ||
const expirationMinutes = Number(req.mpsService.config.jwt_expiration) | ||
const expiration = Math.floor((Date.now() + (1000 * 60 * expirationMinutes)) / 1000) | ||
const signature = jws.sign({ | ||
header: { alg: 'HS256', typ: 'JWT' }, | ||
payload: { | ||
iss: req.mpsService.config.jwt_issuer, | ||
exp: expiration | ||
}, | ||
secret: req.mpsService.config.jwt_secret | ||
}) | ||
res.status(200).send({ token: signature }) | ||
} else { | ||
res.status(401).send({ message: 'Incorrect Username and/or Password!' }) | ||
} | ||
// todo: implement a more advanced authentication system and RBAC | ||
if (username === req.mpsService.config.web_admin_user && password === req.mpsService.config.web_admin_password) { | ||
const expirationMinutes = Number(req.mpsService.config.jwt_expiration) | ||
const expiration = Math.floor((Date.now() + (1000 * 60 * expirationMinutes)) / 1000) | ||
const signature = jws.sign({ | ||
header: { alg: 'HS256', typ: 'JWT' }, | ||
payload: { | ||
iss: req.mpsService.config.jwt_issuer, | ||
exp: expiration | ||
}, | ||
secret: req.mpsService.config.jwt_secret | ||
}) | ||
res.status(200).send({ token: signature }) | ||
} else { | ||
res.status(401).send({ message: 'Incorrect Username and/or Password!' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.