-
Notifications
You must be signed in to change notification settings - Fork 9
/
php-authen.php
41 lines (33 loc) · 1.22 KB
/
php-authen.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
<?php
require_once 'OnionIoT-KeyCloak-PHP/src/KeyCloak/Grant.php';
require_once 'OnionIoT-KeyCloak-PHP/src/KeyCloak/KeyCloak.php';
require_once 'OnionIoT-KeyCloak-PHP/src/KeyCloak/Token.php';
require_once 'includes/backend-call.php';
/*
* gets url from keycloak.js
*/
function Login($username, $password)
{
$config = file_get_contents('keycloak.json');
$kc = new \OnionIoT\KeyCloak\KeyCloak($config);
$kc->grant_from_login($username, $password);
$grant = $kc->grant;
$token = $grant->access_token->_raw;
return $token;
}
/*
* gets url from keycloak.js, gets $usrpwd from backendconfig.json
*/
function CheckToken($token)
{
$config = json_decode(file_get_contents('keycloak.json'), TRUE);
$usrpwd = json_decode(file_get_contents('backendconfig.json'), TRUE);
$tokenCheckResult = CallAPI($config['auth-server-url'] . "/realms/testRealm/protocol/openid-connect/token/introspect", $token, $usrpwd['backend-usrpwd']);
return $tokenCheckResult;
}
if (strlen($_GET['username'])<1){
require_once 'includes/login.php';
} else {
require_once 'includes/authenticate.php';
}
?>