2,15 → 2,18 |
var urlRacine = 'http://www.tela-botanica.org', |
config = { |
prod: { |
urlWidgetNavigation : urlRacine + '/widget:reseau:navigation' |
urlWidgetNavigation : urlRacine + '/widget:reseau:navigation', |
urlBaseAuth = 'https://www.tela-botanica.org/service:annuaire:auth' |
}, |
test: { |
urlWidgetNavigation : urlRacine + '/widget-test:reseau:navigation', |
urlBaseAuth = 'https://www.tela-botanica.org/service:annuaire-test:auth' |
}, |
local: { |
urlWidgetNavigation : 'http://localhost/widget:reseau:navigation' |
urlWidgetNavigation : 'http://localhost/widget:reseau:navigation', |
urlBaseAuth = 'https://localhost/service:annuaire:auth' |
} |
}; |
} |
|
/** |
* Charge la barre de navigation depuis le widget:reseau:navigation dans un <div id="tb-navigation"> , s'il existe |
57,6 → 60,9 |
var zoneSource = div.find('#contenu-source'); |
if (zoneSource) { |
zoneSource.replaceWith(contenu); |
// Chargement de sinformations de connexion SSO |
var urlBaseAuth = config[mode]['urlBaseAuth']; |
chargerStatutSSO(urlBaseAuth); |
} |
}, |
error: function() { |
64,4 → 70,51 |
} |
}); |
} |
}); |
}); |
|
/** |
* |
*/ |
function chargerStatutSSO(urlBaseAuth) { |
// vérification de l'état au chargement |
var urlAuth = urlBaseAuth + '/identite'; |
$.ajax({ |
url: urlAuth, |
type: "GET", |
dataType: 'json', |
xhrFields: { |
withCredentials: true |
} |
}).done(function(data) { |
// connecté |
definirUtilisateur(data.token); |
}); |
} |
|
function definirUtilisateur(jeton) { |
var nomComplet = ''; |
if (jeton != undefined) { |
// décodage jeton |
var jetonDecode = decoderJeton(jeton); |
nomComplet = jetonDecode.intitule; |
} |
// affichage |
$('#bouton-connexion').hide(); |
$('#utilisateur-connecte').show(); |
$('#nom-complet').html(nomComplet); |
} |
|
/** |
* Décodage à l'arrache d'un jeton JWT, ATTENTION CONSIDERE QUE LE |
* JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple |
* Si pb de cross-browser, tenter ceci : https://code.google.com/p/javascriptbase64/ |
* ou ceci : https://code.google.com/p/crypto-js |
*/ |
function decoderJeton(jeton) { |
parts = jeton.split('.'); |
payload = parts[1]; |
payload = atob(payload); |
payload = JSON.parse(payload, true); |
|
return payload; |
} |