so I have a self written php web service for an app.
Now I want to do the same with the web. But I struggle with the login.
I need to call 2 functions of the web service. One to get a login token another one to verify that and request a access token.
So I call them with javascript:
<?php
if(isset($_POST['email']) && isset($_POST['password']))
{
?>
<script>
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://webservice.com/requestLoginToken", false);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(<?php echo "'email=" . urlencode($_POST['email']) . "'"?>);
if(xhttp.status == 401)
document.getElementById("message").innerHTML = xhttp.responseText;
else
{
var loginToken = xhttp.responseText;
var pwHash = loginToken + <?php echo "'" . sha1($_POST['password']) . "'" ?>;
pwHash = sha1(pwHash);
xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://webservice.com/authenticate", false);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send("loginToken=" + loginToken + "&publicHash=" + pwHash);
if(!xhttp.status == 200)
document.getElementById("message").innerHTML = xhttp.responseText;
else
{
var accesstoken = xhttp.responseText;
}
}
</script>
<?php
}
?>
So now I have the access token. But how can I set this now as a session variable of $_SESSION?
Or what is the best way so save this access token during the stay?
I need this token whenever I call the API.