Skip to content

Commit

Permalink
Merge pull request #219 from Jampire/master
Browse files Browse the repository at this point in the history
Add IBM App ID provider
  • Loading branch information
weaverryan authored Feb 7, 2020
2 parents 7362cbd + 6c86ee1 commit 4f71b8a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ via Composer:
| OAuth2 Provider | Install |
| --------------------------------------------------------------------- | ------------------------------------------------------ |
| [Amazon](https://github.com/luchianenco/oauth2-amazon) | composer require luchianenco/oauth2-amazon |
| [AppID](https://github.com/Jampire/oauth2-appid) | composer require jampire/oauth2-appid |
| [Apple](https://github.com/patrickbussmann/oauth2-apple) | composer require patrickbussmann/oauth2-apple |
| [Auth0](https://github.com/RiskioFr/oauth2-auth0) | composer require riskio/oauth2-auth0 |
| [Azure](https://github.com/thenetworg/oauth2-azure) | composer require thenetworg/oauth2-azure |
Expand Down Expand Up @@ -458,6 +459,27 @@ knpu_oauth2_client:
# whether to check OAuth2 "state": defaults to true
# use_state: true
# will create service: "knpu.oauth2.client.appid"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\AppIdClient
# composer require jampire/oauth2-appid
appid:
# must be "appid" - it activates that type!
type: appid
# add and configure client_id and client_secret in parameters.yml
client_id: '%env(OAUTH_APPID_CLIENT_ID)%'
client_secret: '%env(OAUTH_APPID_CLIENT_SECRET)%'
# a route name you'll create
redirect_route: connect_appid_check
redirect_params: {}
# IBM App ID base URL. For example, "https://us-south.appid.cloud.ibm.com/oauth/v4". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started
base_auth_uri: '%env(OAUTH_APPID_BASE_AUTH_URI)%'
# IBM App ID service tenant ID. For example, "1234-5678-abcd-efgh". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started
tenant_id: '%env(OAUTH_APPID_TENANT_ID)%'
# Identity Provider code. Defaults to "saml". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started
# idp: '%env(OAUTH_APPID_IDP)%'
# whether to check OAuth2 "state": defaults to true
# use_state: true
# will create service: "knpu.oauth2.client.apple"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\AppleClient
# composer require patrickbussmann/oauth2-apple
Expand Down
40 changes: 40 additions & 0 deletions src/Client/Provider/AppIdClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* OAuth2 Client Bundle
* Copyright (c) KnpUniversity <http://knpuniversity.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KnpU\OAuth2ClientBundle\Client\Provider;

use Jampire\OAuth2\Client\Provider\AppIdResourceOwner;
use KnpU\OAuth2ClientBundle\Client\OAuth2Client;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use League\OAuth2\Client\Token\AccessToken;

/**
* Class AppIdClient.
*
* @author Dzianis Kotau <jampire.blr@gmail.com>
*/
class AppIdClient extends OAuth2Client
{
/**
* @return AppIdResourceOwner|ResourceOwnerInterface
*/
public function fetchUserFromToken(AccessToken $accessToken)
{
return parent::fetchUserFromToken($accessToken);
}

/**
* @return AppIdResourceOwner|ResourceOwnerInterface
*/
public function fetchUser()
{
return parent::fetchUser();
}
}
2 changes: 2 additions & 0 deletions src/DependencyInjection/KnpUOAuth2ClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace KnpU\OAuth2ClientBundle\DependencyInjection;

use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\AmazonProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\AppIdProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\AppleProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\Auth0ProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\AzureProviderConfigurator;
Expand Down Expand Up @@ -86,6 +87,7 @@ class KnpUOAuth2ClientExtension extends Extension
/** @var array */
private static $supportedProviderTypes = [
'amazon' => AmazonProviderConfigurator::class,
'appid' => AppIdProviderConfigurator::class,
'apple' => AppleProviderConfigurator::class,
'auth0' => Auth0ProviderConfigurator::class,
'azure' => AzureProviderConfigurator::class,
Expand Down
79 changes: 79 additions & 0 deletions src/DependencyInjection/Providers/AppIdProviderConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* OAuth2 Client Bundle
* Copyright (c) KnpUniversity <http://knpuniversity.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace KnpU\OAuth2ClientBundle\DependencyInjection\Providers;

use Symfony\Component\Config\Definition\Builder\NodeBuilder;

/**
* Class AppIdProviderConfigurator.
*
* @author Dzianis Kotau <jampire.blr@gmail.com>
*/
class AppIdProviderConfigurator implements ProviderConfiguratorInterface
{
public function buildConfiguration(NodeBuilder $node)
{
$node
->scalarNode('base_auth_uri')
->isRequired()
->info('IBM App ID base URL. For example, "https://us-south.appid.cloud.ibm.com/oauth/v4". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started')
->example('base_auth_uri: \'%env(OAUTH_APPID_BASE_AUTH_URI)%\'')
->end()
->scalarNode('tenant_id')
->isRequired()
->info('IBM App ID service tenant ID. For example, "1234-5678-abcd-efgh". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started')
->example('tenant_id: \'%env(OAUTH_APPID_TENANT_ID)%\'')
->end()
->scalarNode('idp')
->defaultValue('saml')
->info('Identity Provider code. Defaults to "saml". More details at https://cloud.ibm.com/docs/services/appid?topic=appid-getting-started')
->example('idp: \'%env(OAUTH_APPID_IDP)%\'')
->end()
;
}

public function getProviderClass(array $configuration)
{
return 'Jampire\OAuth2\Client\Provider\AppIdProvider';
}

public function getClientClass(array $config)
{
return 'KnpU\OAuth2ClientBundle\Client\Provider\AppIdClient';
}

public function getProviderOptions(array $configuration)
{
return [
'clientId' => $configuration['client_id'],
'clientSecret' => $configuration['client_secret'],
'baseAuthUri' => $configuration['base_auth_uri'],
'tenantId' => $configuration['tenant_id'],
'redirectRoute' => $configuration['redirect_route'],
'idp' => $configuration['idp'],
];
}

public function getPackagistName()
{
return 'jampire/oauth2-appid';
}

public function getLibraryHomepage()
{
return 'https://github.com/Jampire/oauth2-appid';
}

public function getProviderDisplayName()
{
return 'AppID';
}
}

0 comments on commit 4f71b8a

Please sign in to comment.