-
Notifications
You must be signed in to change notification settings - Fork 31
/
locallib.php
37 lines (29 loc) · 1.05 KB
/
locallib.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
<?php
function oauth_add_wordpress_client($client_id, $url) {
global $DB;
$url = trim($url);
if (substr($url, -1) !== '/') {
$url .= '/';
}
$record = new stdClass();
$record->redirect_uri = $url . 'wp-content/plugins/wordpress-social-login/hybridauth/callbacks/moodle.php';
$record->grant_types = 'authorization_code';
$record->scope = 'user_info ';
$record->user_id = '';
// do save
$record->client_id = $client_id;
$record->client_secret = generate_secret();
return $DB->insert_record('oauth_clients', $record);
}
function generate_secret() {
// Get a bunch of random characters from the OS
$fp = fopen('/dev/urandom', 'rb');
$entropy = fread($fp, 32);
fclose($fp);
// Takes our binary entropy, and concatenates a string which represents the current time to the microsecond
$entropy .= uniqid(mt_rand(), true);
// Hash the binary entropy
$hash = hash('sha512', $entropy);
// Chop and send the first 80 characters back to the client
return substr($hash, 0, 48);
}