Skip to content

Commit

Permalink
step 3 : userToken - init
Browse files Browse the repository at this point in the history
  • Loading branch information
Ballinette committed Oct 12, 2019
1 parent b3889f1 commit d5e06f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
const {
userAuthorize,
loginRedirect,
userToken,
} = require('./controllers/oidcProvider');

const app = express();
Expand Down Expand Up @@ -49,6 +50,7 @@ app.get('/logout', localLogout);
/**** OIDC End points ****/
app.get('/user/authorize', userAuthorize);
app.get('/user/loginRedirect', loginRedirect);
app.post('/user/token', userToken);

/**** END OIDC End points ****/

Expand Down
31 changes: 31 additions & 0 deletions controllers/oidcProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,38 @@ const loginRedirect = (req, res) => {
}
}

const userToken = (req, res) => {
console.log('USER TOKEN', req.body);

// check the required parameters
for (const field of ['client_id', 'client_secret', 'code']) {
if (!req.body[field]) {
console.error(`missing "${field}" parameter`);
return res.sendStatus(400);
}
}

// check client config:
const
{client_id, client_secret, code} = req.body,
client = findClient(client_id);
if (! client) {
console.error('Client ID not found');
return res.sendStatus(400);
}
if (client_secret !== client.client_secret) {
console.error('Client Secret mismatch');
return res.sendStatus(400);
}

const tokenData = {}; //@TODO: populate with idToken and AccessToken

return res.json(tokenData);
};


module.exports = {
userAuthorize,
loginRedirect,
userToken,
}

0 comments on commit d5e06f3

Please sign in to comment.