Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Important details for oauth2 documentation #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth/authentication-oauth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Choose which adapter to use for the OAuth2 dataset. You can manage the dataset u
relational database (the OAuth2 library API Tools utilizes uses
[PDO](http://www.php.net/manual/en/book.pdo.php) specifically) or
[MongoDB](https://www.mongodb.org/). Other adapters are available such as
[api-tools-oauth2-doctrine](https://github.com/API-Skeletons/api-tools-oauth2-doctrine).
[oauth2-doctrine](https://github.com/API-Skeletons/oauth2-doctrine).

When you select the OAuth2 PDO adapter, you will see the following form:

Expand Down
15 changes: 14 additions & 1 deletion auth/user-differentiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Module

// Add Authentication Adapter for session
$defaultAuthenticationListener = $container->get(DefaultAuthenticationListener::class);
$defaultAuthenticationListener->attach(new Authentication\AuthenticationAdapter());
$defaultAuthenticationListener->attach(new Authentication\Adapter\SessionAdapter());
}
}
```
Expand Down Expand Up @@ -252,6 +252,15 @@ So we need to add Authorization to the application:
First we'll extend the onBootstrap we just created:

```php
namespace Application;

use Laminas\ApiTools\MvcAuth\Authentication\DefaultAuthenticationListener;
use Laminas\EventManager\EventInterface;

use Laminas\ApiTools\MvcAuth\MvcAuthEvent;

class Module
{
public function onBootstrap(EventInterface $e)
{
$app = $e->getApplication();
Expand All @@ -269,6 +278,8 @@ First we'll extend the onBootstrap we just created:
100
);
}

}
```

And we need to create the `AuthorizationListener` we just configured:
Expand All @@ -285,6 +296,8 @@ final class AuthorizationListener
public function __invoke(MvcAuthEvent $mvcAuthEvent)
{
$authorization = $mvcAuthEvent->getAuthorizationService();

$authorization->addRole('user');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment on what this role may mean? (magic constants are problematic, even in examples)

Copy link
Author

@webermax webermax Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example code fails with a fatal error about missing role "user" when executing it without adding the new role:

https://discourse.laminas.dev/t/role-user-not-found-following-authorizations-docs/1397


// Deny from all
$authorization->deny();
Expand Down
2 changes: 1 addition & 1 deletion intro/first-rest-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ lists, and we are not defining those operations.

How will we get the `$mapper` into the resource? For that, we'll edit our factory. Open
the file `module/Status/src/V1/Rest/Status/StatusResourceFactory.php` in an editor,
and modify it so it reads as follows (you should only need to change the `return` line inside the
and modify it so it reads as follows (add `use StatusLib\Mapper;` and change the `return` line inside the
`__invoke()` method):

```php
Expand Down