forked from vlex/remote_auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_auth.php
40 lines (34 loc) · 1.29 KB
/
remote_auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* Returns a URL that grants access to vLex without explicitly signing in
*
* @since Unknown
*
* @param array $data : Containing ["name"] The name of the user - ["email"]
* The email address of the user - ["account_id"] The corporate account id
* of the company - ["token"] The corporate account token of the company
* @return string : The URL granting access to vLex or NULL when errors occur
*/
function remote_auth($data) {
// Set default remote authorization path
$REMOTE_AUTH_URL = "http://vlex.com/session/remote_auth";
// Sort $data checking that required parameters are present
$keys = array("name", "email", "account_id", "token");
foreach($keys as $key) {
if(!isset($data[$key])) throw new Exception("Missing parameter: $key");
$values[$key] = $data[$key];
}
// Add timestamp
$values["timestamp"] = time();
// Add hash from the concatenated data
$values["hash"] = md5(implode($values));
// delete token
unset($values["token"]);
// Generate the query and return the URL
$query = http_build_query($values); // name=yourname&email=...
return "$REMOTE_AUTH_URL?$query";
}
// Example:
// $my_data = array("account_id" => "1234", "name" => "tester", "token" => "TOKEN", "email" => "[email protected]");
// echo(remote_auth($my_data)."\n");
?>