Skip to content

Commit

Permalink
Allow user to change where attriubtes are found in JSON on HTTP auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Daynnnnn committed Aug 3, 2021
1 parent f96cf80 commit be736cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,31 @@ An ldap search will be made of the `base_dn` to find the user. If the user is fo

`endpoint`: `(string)` Address on which login will be attempted

`result`: `(array)` Where the success status and full name of the user can be found in the JSON response, example:

If your JSON response looks like this:

```
{
"result": true,
"data": {
"name": "Daniel Pegg"
}
}
```

Your result array should look like this:

```
result => [
'success' => 'result',
'name' => 'data.name',
],
```

### Description

A POST request will be sent to the endpoint with the attributes of `email` and `password`. The expected response is JSON, with a `result` item containing true or false, and a `data.name` item containing a name for the user.
A POST request will be sent to the endpoint with the attributes of `email` and `password`. The expected response is JSON, and should contain the success status of the credentials, and if the success status is true, the full name of a user.

# Extending

Expand Down
6 changes: 3 additions & 3 deletions src/AuthServices/HttpAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Daynnnnn\Statamic\Auth\ForwardAuth\AuthServices;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;


class HttpAuthService implements AuthServiceContract
{
protected $config;
Expand All @@ -19,12 +19,12 @@ public function checkCredentialsAgainstForwardAuth(array $credentials) {
}

public function credentialsValidAgainstForwardAuth() {
return $this->forwardAuthUser['result'];
return Arr::get($this->forwardAuthUser, $this->config['config']['response']['success']);
}

public function userData() {
return array_merge($this->config['data'], [
'name' => $this->forwardAuthUser['data']['name'],
'name' => Arr::get($this->forwardAuthUser, $this->config['config']['response']['name']),
'forward_auth' => true,
]);
}
Expand Down

0 comments on commit be736cf

Please sign in to comment.