dingo / dingo/api

How to configure HTTP Basic auth?

Open
#1,222 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hello!

In wiki:
https://github.com/dingo/api/wiki/Authentication

I found that I need to put this code somewhere:

``` php
app('Dingo\Api\Auth\Auth')->extend('basic', function ($app) {
return new Dingo\Api\Auth\Provider\Basic($app['auth'], 'email');
});
```

Also I found an issue with same problem:
https://github.com/dingo/api/issues/694

My test route:

``` php
// example of protected route
$api->get('protected', ['middleware' => ['api.auth'], function () {
return \App\Employee::all();
}]);
```

I tried to put in `App\Providers\AppServiceProvider.php`:

``` php
public function boot()
{
$this->app('Dingo\Api\Auth\Auth')->extend('basic', function ($app) {
return new Dingo\Api\Auth\Provider\Basic($app['auth'], 'email');
});
}
```

Route call shows error:

```
FatalErrorException in AppServiceProvider.php line 17:
Call to undefined method App\Providers\AppServiceProvider::app()
```

Also tried to put in `config/api.php` this code:

``` php
'auth' => [
'basic' => function ($app) {
return new Dingo\Api\Auth\Provider\Basic($app['auth']);
}
],
```

Error:

``` json
"message": "Call to undefined method Closure::authenticate()",
"code": 1,
"status_code": 500,
```

How to configure it?

Env:
Laravel 5.3
Latest Dingo

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.