oauth->key."&client_secret=".$config->oauth->secret."&scope=read:accounts&redirect_uri=".$reqirectUri;
curl_setopt($request, CURLOPT_POSTFIELDS, $options);
$response = curl_exec($request);
curl_close($request);
$Auth = json_decode($response);
if(isset($Auth->token_type)){
// Valid Auth?
$request = curl_init();
curl_setopt($request, CURLOPT_URL, "https://hackers.town/api/v1/accounts/verify_credentials");
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_HTTPHEADER, array(
"Authorization: ".$Auth->token_type." ".$Auth->access_token
));
$response = curl_exec($request);
curl_close($request);
$User = json_decode($response);
if (isset($User->id)){
// Congrats!
$AuthToken = $Auth->access_token;
$UserName = $User->display_name;
$UserId = $User->id;
}else{
// invalid auth
$AuthToken = "BadUser";
$ErrorDesc = "User Not Found";
}
}else{
// invalid auth
if(isset($_COOKIE["oa_retries"])){
$retries = $_COOKIE["oa_retries"];
if($retries >= 3){
$AuthToken = "BadUser";
$ErrorDesc = "Invalid OAuth";
setcookie("oa_retries", 0, time()+3600);
}else{
$retries++;
setcookie("oa_retries", $retries, time()+3600);
$AuthToken = "BadOauthRetry";
$ErrorDesc = "Invalid OAuth Retry";
}
}else{
$AuthToken = "BadOauth";
$ErrorDesc = "Invalid OAuth Retry";
setcookie("oa_retries", 1, time()+3600);
}
}
// revoke token after usage
?>
>
>
Setup an account SSH key
>