README.md 1.39 KB
Newer Older
Marcus Povey's avatar
Marcus Povey committed
1
# Keycloak Account API PHP bindings
Marcus Povey's avatar
Marcus Povey committed
2
3
4

This repository is the very initial outline for interfacing with the Keycloak account_api.

Marcus Povey's avatar
Marcus Povey committed
5
6
7
8
9
## Usage

To add this to your project: 

`composer require aria-php/keycloak-api`
Marcus Povey's avatar
Marcus Povey committed
10

Marcus Povey's avatar
Marcus Povey committed
11
12
13
14
## Supported features

This API wrapper supports the ability to:

Marcus Povey's avatar
Marcus Povey committed
15
16
17
### Account API

* Retrieve the profile of your user (as identified by your `access_token` sent as a bearer token)
Marcus Povey's avatar
Marcus Povey committed
18
19
20
* Update the profile
* Set the user's password

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
e.g.

```
use ARIA\KeycloakAPI\AccountAPI;

...

$api = new AccountAPI($client_id, $secret, 'master', 'http://localhost:8080');
$api->setBearer($access_token);


$profile = $api->getProfile();


// Make your updates here


$api->setProfile($profile);


```

Marcus Povey's avatar
Marcus Povey committed
43
## Authentication
Marcus Povey's avatar
Marcus Povey committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

Your user is identified by obtaining an access token from keycloak for the user, and then passing it as a bearer token. 

Note: this is the `access_token`, not the `id_token`.

## Testing 

In order to run the unit tests you need to set up some environment variables:

* `KEYCLOAK_USER` is the user you're trying to connect to 
* `KEYCLOAK_PASS` their password
* `KEYCLOAK_REALM` the keycloak realm (e.g. "master")
* `KEYCLOAK_CLIENT_ID` the keycloak client id (e.g. "account")
* `KEYCLOAK_SECRET` the client secret
* `KEYCLOAK_BASEURL` the base URL, e.g. "http://localhost:8080"

Marcus Povey's avatar
Marcus Povey committed
60
You will also need to enable "Direct access grants" for your client.
Marcus Povey's avatar
Marcus Povey committed
61
62
63

## Licence 

64
LGPLv3 - Please see LICENSE.txt for details.