Skip to content

Commit

Permalink
Fix bug refresh token and sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
apozohue10 committed Mar 1, 2019
1 parent 37fa8fa commit 5ac77f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions controllers/saml2/saml2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config_attributes_representative = Object.keys(

// Create identity provider
const idp_options = {
sso_login_url: config.eidas.node_host,
sso_login_url: config.eidas.node_host || config.eidas.idp_host, // config.eidas.idp_host should be deprectated
sso_logout_url: 'https://' + config.eidas.gateway_host + '/saml2/logout',
certificates: [],
};
Expand Down Expand Up @@ -302,7 +302,7 @@ exports.login = function(req, res) {
delete req.body.password;
delete req.query;

res.redirect(307, config.eidas.node_host);
res.redirect(307, config.eidas.node_host || config.eidas.idp_host); // config.eidas.idp_host should be deprectated
};

// POST /idm/applications/:application_id/saml2/login -- Response from eIDAs with user credentials
Expand Down
47 changes: 26 additions & 21 deletions models/model_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,24 +358,25 @@ function storeToken(token, client, identity, jwt) {
}
}

return Promise.all([
token.refreshToken
? oauth_refresh_token.create({
// no refresh token for client_credentials
refresh_token: token.refreshToken,
expires: token.refreshTokenExpiresAt,
valid: true,
oauth_client_id: client.id,
user_id,
iot_id,
authorization_code: token.authorizationCode
? token.authorizationCode
: null,
scope: token.scope,
})
: [],
!jwt
? oauth_access_token.create({
let refresh_token_promise = token.refreshToken
? oauth_refresh_token.create({
// no refresh token for client_credentials
refresh_token: token.refreshToken,
expires: token.refreshTokenExpiresAt,
valid: true,
oauth_client_id: client.id,
user_id,
iot_id,
authorization_code: token.authorizationCode
? token.authorizationCode
: null,
scope: token.scope,
})
: Promise.resolve();

let access_token_promise = !jwt
? refresh_token_promise.then(
oauth_access_token.create({
access_token: token.accessToken,
expires: token.accessTokenExpiresAt,
valid: true,
Expand All @@ -388,7 +389,10 @@ function storeToken(token, client, identity, jwt) {
: null,
scope: token.scope === 'all' ? null : token.scope,
})
: [],
)
: [];

let user_autho_app_promise =
user_id && config_oauth2.ask_authorization
? user_authorized_application.findOrCreate({
// User has enable application to read their information
Expand All @@ -398,8 +402,9 @@ function storeToken(token, client, identity, jwt) {
oauth_client_id: client.id,
},
})
: [],
])
: [];

return Promise.all([access_token_promise, user_autho_app_promise])
.then(function() {
if (user_id || iot_id) {
token[identity.dataValues.type] = identity.dataValues.type;
Expand Down
6 changes: 1 addition & 5 deletions routes/web/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ router.delete(
web_session_controller.login_required,
web_session_controller.destroy
);
router.delete(
'/external_logout',
web_session_controller.login_required,
web_session_controller.external_destroy
);
router.delete('/external_logout', web_session_controller.external_destroy);

module.exports = router;

0 comments on commit 5ac77f3

Please sign in to comment.