# Basic Authentication with Slim & Eloquent

**URL:** <https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662>\
**Category:** Questions\
**Created:** [August 27, 2016, 9:36am UTC](https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662 "2016-08-27T09:36:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![didi](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@didi](https://discourse.slimframework.com/u/didi)\
**Post date:** [August 27, 2016, 9:36am UTC](https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662/1 "2016-08-27T09:36:40Z")

</div>

Hi, i want to use basic authentication with my rest api. I want to check every time my api is called if it is a valid user.  
When i send a get with Authentication header there is nothing in my request object… here’s my code:

```
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

$app->get('/api/...', function (Request $request, Response $response) {
    var_dump($request->getHeaders());
    return ...;
});

```

Unfortunately there is no authentication in my header… i send the following in my header:  
`Authorization:Basic dGVzdDp0ZXN0MTIz`

How can i use basic auth (in combination with eloquent)?

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [August 27, 2016, 1:49pm UTC](https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662/2 "2016-08-27T13:49:14Z")

</div>

How is your PHP environment setup? For example, I recall if PHP is running through Apache mod\_cgi you will not have access to the authorization headers. For Basic Auth, I’m using @tuupola’s [slim-basic-auth](https://github.com/tuupola/slim-basic-auth) package and it works quite well.

---

<div class="post-metadata">

**Author:** ![didi](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@didi](https://discourse.slimframework.com/u/didi)\
**Post date:** [August 27, 2016, 2:26pm UTC](https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662/3 "2016-08-27T14:26:46Z")

</div>

Ah okay, i’m using cgi… Can i use tuupola’s package with cgi?

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [August 27, 2016, 5:44pm UTC](https://discourse.slimframework.com/t/basic-authentication-with-slim-eloquent/662/4 "2016-08-27T17:44:27Z")

</div>

I’m not sure, but it should be pretty fast to pull it in and give it a go.
