Skip to content

Commit

Permalink
Fix chapter order and add 'keycloak.preferred_username' option (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlauciani authored Mar 15, 2024
1 parent aa71dbe commit 82a19f3
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,6 @@ Auth::hasAnyRole('myapp-frontend', ['myapp-frontend-role1', 'myapp-frontend-role
Auth::hasAnyRole('myapp-backend', ['myapp-frontend-role1', 'myapp-frontend-role2']) // false
```

# Acting as a Keycloak user in tests

As an equivelant feature like `$this->actingAs($user)` in Laravel, with this package you can use `KeycloakGuard\ActingAsKeycloakUser` trait in your test class and then use `actingAsKeycloakUser()` method to act as a user and somehow skip the Keycloak auth:

```php
use KeycloakGuard\ActingAsKeycloakUser;

public test_a_protected_route()
{
$this->actingAsKeycloakUser()
->getJson('/api/somewhere')
->assertOk();
}
```

#### Scope
Example decoded payload:
```json
Expand Down Expand Up @@ -338,6 +323,23 @@ Auth::hasAnyScope(['scope-a', 'scope-d']) // true
Auth::hasAnyScope(['scope-f', 'scope-k']) // false
```

# Acting as a Keycloak user in tests

As an equivelant feature like `$this->actingAs($user)` in Laravel, with this package you can use `KeycloakGuard\ActingAsKeycloakUser` trait in your test class and then use `actingAsKeycloakUser()` method to act as a user and somehow skip the Keycloak auth:

```php
use KeycloakGuard\ActingAsKeycloakUser;

public test_a_protected_route()
{
$this->actingAsKeycloakUser()
->getJson('/api/somewhere')
->assertOk();
}
```

If you are not using `keycloak.load_user_from_database` option, set `keycloak.preferred_username` with a valid `preferred_username` for tests.

# Contribute

You can run this project on VSCODE with Remote Container. Make sure you will use internal VSCODE terminal (inside running container).
Expand Down

0 comments on commit 82a19f3

Please sign in to comment.