Subversion Repositories Applications.annuaire

Compare Revisions

No changes between revisions

Ignore whitespace Rev 567 → Rev 568

/branches/v1.4-baleine/jrest/services/Auth.php
194,8 → 194,13
$acces = $this->verifierAcces($login, $password);
if ($acces === false) {
$this->detruireCookie();
$this->erreur("authentication failed", 401);
}
if(!empty($_GET['redirect_url'])) {
header('Location: '.$_GET['redirect_url']);
} else {
$this->erreur("authentication failed", 401);
}
 
}
// infos utilisateur
$util = new Utilisateur($this->config);
$infos = $util->getIdentiteParCourriel($login);
211,15 → 216,20
$jwt = $this->creerJeton($login, $infos[$login]);
// création du cookie
$this->creerCookie($jwt);
// envoi
$this->envoyerJson(array(
"session" => true,
"token" => $jwt,
"duration" => intval($this->dureeJeton),
"token_id" => $this->nomCookie,
"last_modif" => $infos[$login]['dateDerniereModif']
));
}
if(!empty($_GET['redirect_url'])) {
$this->redirigerAvecJeton($_GET['redirect_url'], $jwt);
} else {
// envoi
$this->envoyerJson(array(
"session" => true,
"token" => $jwt,
"duration" => intval($this->dureeJeton),
"token_id" => $this->nomCookie,
"last_modif" => $infos[$login]['dateDerniereModif']
));
}
}
 
/**
* Détruit le cookie et renvoie un jeton vide ou NULL - le client
231,12 → 241,16
$this->detruireCookie();
// envoi d'un jeton null
$jwt = null;
$this->envoyerJson(array(
"session" => false,
"token" => $jwt,
"token_id" => $this->nomCookie
));
}
if(!empty($_GET['redirect_url'])) {
header('Location: '.$_GET['redirect_url']);
} else {
$this->envoyerJson(array(
"session" => false,
"token" => $jwt,
"token_id" => $this->nomCookie
));
}
}
 
/**
* Renvoie un jeton rafraîchi (durée de validité augmentée de $this->dureeJeton
292,18 → 306,39
$erreur = ($erreur == "" ? "no token or cookie" : "invalid token in cookie / invalid or expired token in Authorization header or parameter <token>");
}
}
// renvoi jeton
if ($jetonRetour === null) {
$this->erreur($erreur);
} else {
$this->envoyerJson(array(
"session" => true,
"token" => $jetonRetour,
"duration" => intval($this->dureeJeton),
"token_id" => $this->nomCookie
));
if(!empty($_GET['redirect_url'])) {
if ($jetonRetour != null) {
$this->redirigerAvecJeton($_GET['redirect_url'], $jetonRetour);
} else {
header('Location: '.$_GET['redirect_url']);
}
} else {
// renvoi jeton
if ($jetonRetour === null) {
$this->erreur($erreur);
} else {
$this->envoyerJson(array(
"session" => true,
"token" => $jetonRetour,
"duration" => intval($this->dureeJeton),
"token_id" => $this->nomCookie
));
}
}
}
}
protected function redirigerAvecJeton($url, $jetonRetour) {
// dans le cas où une url de redirection est précisée,
// on est généreux et on précise le jeton dans le header et le get
if ($jetonRetour != null) {
$url_redirection = $_GET['redirect_url'];
$separateur = (parse_url($url_redirection, PHP_URL_QUERY) == NULL) ? '?' : '&';
$url_redirection .= $separateur.'Authorization='.$jetonRetour;
header('Authorization: '.$jetonRetour);
}
header('Location: '.$url_redirection);
exit;
}
 
/**
* Vérifie si un jeton est valide; retourne true si oui, une erreur avec
/branches/v1.4-baleine/.
Property changes:
Modified: svn:mergeinfo
Merged /trunk:r559