Skip to content

Instantly share code, notes, and snippets.

@mrManner
Created June 11, 2020 12:35
Show Gist options
  • Select an option

  • Save mrManner/696e5c6d0faa0efe19c6dca972e8f02f to your computer and use it in GitHub Desktop.

Select an option

Save mrManner/696e5c6d0faa0efe19c6dca972e8f02f to your computer and use it in GitHub Desktop.
<?php
/**
* @param string $username
* @param string $password
*/
function login($username, $password): array
// AUTH MOT SCOUTNET
$scoutnetHostname = "www.scoutnet.se";
$authUrl = "https://{$scoutnetHostname}/api/authenticate";
$postData = http_build_query(
[
'username' => $username,
'password' => $password
]
);
$opts = [
'http' =>
[
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postData
]
];
$context = stream_context_create($opts);
$authResult = file_get_contents($authUrl, false, $context);
$authResultObj = json_decode($authResult, false, 512, JSON_THROW_ON_ERROR);
var_dump($authResultObj);
//GET ADDITIONAL ATTRIBUTES FROM USER PROFILE
$profileUrl = "https://{$scoutnetHostname}/api/get/profile";
print($authResultObj->token);
$options = [
'http' => [
'method' => 'POST',
'header' => "Authorization: Bearer {$authResultObj->token}"
]
];
$context = stream_context_create($options);
$memberResult = file_get_contents($profileUrl, false, $context);
var_dump($memberResult);
$memberResultObj = json_decode($memberResult, false, 512, JSON_THROW_ON_ERROR);
}
login("3225431", "Quia1yei eeShoeS9 oqu8zoNg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment