Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jampire committed Dec 12, 2019
1 parent dee99f1 commit fba04ce
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
37 changes: 37 additions & 0 deletions docs/FrameworkIntegration/Symfony/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,43 @@ class AppIdController extends AbstractController
}
```

Create HomeController

```php
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
* Class HomeController
*
* @author Dzianis Kotau <jampire.blr@gmail.com>
* @package App\Controller
*/
class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
* @return JsonResponse
* @author Dzianis Kotau <jampire.blr@gmail.com>
*/
public function home(): JsonResponse
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

return new JsonResponse([
'name' => $this->getUser()->getFullName(),
'email' => $this->getUser()->getEmail(),
]);
}
}

```

### Step 3 - Add the guard authenticator

Create IBM App ID authenticator guard. Below code block is published under MIT license. Please see [License File](https://github.com/Jampire/oauth2-appid/blob/master/LICENSE) for more information.
Expand Down
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ composer require jampire/oauth2-appid

Usage is the same as The League's OAuth client, using `\Jampire\OAuth2\Client\Provider\AppIdProvider` as the provider.

Use `base_auth_uri` to specify the IBM App ID base server URL. You can lookup the correct value from the Application settings of your IBM App ID service under `oAuthServerUrl` without `tenantId` section, eg. `https://us-south.appid.cloud.ibm.com/oauth/v4`.
Use `baseAuthUri` to specify the IBM App ID base server URL. You can lookup the correct value from the Application settings of your IBM App ID service under `oAuthServerUrl` without `tenantId` section, eg. `https://us-south.appid.cloud.ibm.com/oauth/v4`.

Use `tenant_id` to specify the IBM App ID tenant ID. You can lookup the correct value from the Application settings of your IBM App ID service under `tenantId`, eg. `abc-zyz-123`.
Use `tenantId` to specify the IBM App ID tenant ID. You can lookup the correct value from the Application settings of your IBM App ID service under `tenantId`, eg. `abc-zyz-123`.

All other values you can find in Application settings of your IBM App ID service under.

Expand All @@ -49,8 +49,8 @@ session_start();

try {
$provider = new AppIdProvider([
'base_auth_uri' => '{base_auth_uri}',
'tenant_id' => '{tenant_id}',
'baseAuthUri' => '{baseAuthUri}',
'tenantId' => '{tenantId}',
'clientId' => '{clientId}',
'clientSecret' => '{clientSecret}',
'redirectUri' => '{redirectUri}',
Expand Down Expand Up @@ -92,10 +92,10 @@ try {

// We have an access token, which we may use in authenticated
// requests against the service provider's API.
echo '<b>Access Token:</b> ', $accessToken->getToken() , '<br>';
echo '<b>Refresh Token:</b> ' , $accessToken->getRefreshToken() , '<br>';
echo '<b>Expired in:</b> ' , $accessToken->getExpires() , '<br>';
echo '<b>Already expired?</b> ' , ($accessToken->hasExpired() ? 'expired' : 'not expired') , '<br>';
echo '<b>Access Token:</b> ', $accessToken->getToken(), '<br>';
echo '<b>Refresh Token:</b> ', $accessToken->getRefreshToken(), '<br>';
echo '<b>Expired in:</b> ', $accessToken->getExpires(), '<br>';
echo '<b>Already expired?</b> ', ($accessToken->hasExpired() ? 'expired' : 'not expired'), '<br>';

// Using the access token, we may look up details about the
// resource owner.
Expand Down
12 changes: 12 additions & 0 deletions src/Provider/AppIdProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class AppIdProvider extends AbstractProvider
/** @var string */
protected $idp;

/** @var string */
protected $redirectRouteName;

/**
* AppIdProvider constructor.
*
Expand Down Expand Up @@ -174,6 +177,15 @@ public function getIdp(): string
return $this->idp;
}

/**
* @author Dzianis Kotau <jampire.blr@gmail.com>
* @return string
*/
public function getRedirectRouteName(): ?string
{
return $this->redirectRouteName;
}

/**
* Returns the default scopes used by this provider.
*
Expand Down
25 changes: 25 additions & 0 deletions tests/src/Provider/AppIdProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,29 @@ public function testErrorInitialization(): void
'redirectUri' => $this->redirectUri,
]);
}

/**
* @author Dzianis Kotau <jampire.blr@gmail.com>
*/
public function testEmptyRedirectRouteName(): void
{
$this->assertEmpty($this->provider->getRedirectRouteName());
}

/**
* @author Dzianis Kotau <jampire.blr@gmail.com>
*/
public function testRedirectRouteName(): void
{
$provider = new AppIdProvider([
'baseAuthUri' => $this->baseAuthUri,
'tenantId' => $this->tenantId,
'clientId' => $this->clientId,
'clientSecret' => $this->clientSecret,
'redirectUri' => $this->redirectUri,
'redirectRouteName' => 'mock_redirect_route_name',
]);

$this->assertEquals('mock_redirect_route_name', $provider->getRedirectRouteName());
}
}

0 comments on commit fba04ce

Please sign in to comment.