Skip to content

Commit

Permalink
Merge pull request #268 from foxworth42/add-okta-client
Browse files Browse the repository at this point in the history
Add Okta client
  • Loading branch information
weaverryan authored Oct 10, 2020
2 parents 6dea4ca + 38618ff commit 8ede972
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ via Composer:
| [Microsoft](https://github.com/stevenmaguire/oauth2-microsoft) | composer require stevenmaguire/oauth2-microsoft |
| [Mollie](https://github.com/mollie/oauth2-mollie-php) | composer require mollie/oauth2-mollie-php |
| [Odnoklassniki](https://github.com/rakeev/oauth2-odnoklassniki) | composer require aego/oauth2-odnoklassniki |
| [Okta](https://github.com/foxworth42/oauth2-okta) | composer require foxworth42/oauth2-okta |
| [Paypal](https://github.com/stevenmaguire/oauth2-paypal) | composer require stevenmaguire/oauth2-paypal |
| [PSN](https://github.com/larabros/oauth2-psn) | composer require larabros/oauth2-psn |
| [Salesforce](https://github.com/stevenmaguire/oauth2-salesforce) | composer require stevenmaguire/oauth2-salesforce |
Expand Down Expand Up @@ -1079,6 +1080,23 @@ knpu_oauth2_client:
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.okta"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\OktaClient
# composer require foxworth42/oauth2-okta
okta:
# must be "okta" - it activates that type!
type: okta
# add and set these environment variables in your .env files
client_id: '%env(OAUTH_OKTA_CLIENT_ID)%'
client_secret: '%env(OAUTH_OKTA_CLIENT_SECRET)%'
# a route name you'll create
redirect_route: connect_okta_check
redirect_params: {}
# Issuer URI from Okta
issuer: https://mycompany.okta.com/oauth2/default
# whether to check OAuth2 "state": defaults to true
# use_state: true

# will create service: "knpu.oauth2.client.paypal"
# an instance of: KnpU\OAuth2ClientBundle\Client\Provider\PaypalClient
# composer require stevenmaguire/oauth2-paypal
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
},
"suggest": {
"symfony/security-guard": "For integration with Symfony's Guard Security layer"
},
"scripts": {
"test": "simple-phpunit && phpstan analyze"
}
}
34 changes: 34 additions & 0 deletions src/Client/Provider/OktaClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 Foxworth42\OAuth2\Client\Provider\OktaUser;
use KnpU\OAuth2ClientBundle\Client\OAuth2Client;
use League\OAuth2\Client\Token\AccessToken;

class OktaClient extends OAuth2Client
{
/**
* @return OktaUser|\League\OAuth2\Client\Provider\ResourceOwnerInterface
*/
public function fetchUserFromToken(AccessToken $accessToken)
{
return parent::fetchUserFromToken($accessToken);
}

/**
* @return OktaUser|\League\OAuth2\Client\Provider\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 @@ -48,6 +48,7 @@
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\MicrosoftProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\MollieProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\OdnoklassnikiProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\OktaProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\PaypalProviderConfigurator;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderConfiguratorInterface;
use KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderWithoutClientSecretConfiguratorInterface;
Expand Down Expand Up @@ -128,6 +129,7 @@ class KnpUOAuth2ClientExtension extends Extension
'microsoft' => MicrosoftProviderConfigurator::class,
'mollie' => MollieProviderConfigurator::class,
'odnoklassniki' => OdnoklassnikiProviderConfigurator::class,
'okta' => OktaProviderConfigurator::class,
'paypal' => PaypalProviderConfigurator::class,
'psn' => PsnProviderConfigurator::class,
'salesforce' => SalesforceProviderConfigurator::class,
Expand Down
65 changes: 65 additions & 0 deletions src/DependencyInjection/Providers/OktaProviderConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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 OktaProviderConfigurator implements ProviderConfiguratorInterface
{
public function buildConfiguration(NodeBuilder $node)
{
$node
->scalarNode('issuer')
->isRequired()
->info('Issuer URI from Okta')
->example('issuer: https://mycompany.okta.com/oauth2/default')
->end();
}

public function getProviderClass(array $config)
{
return 'Foxworth42\OAuth2\Client\Provider\Okta';
}

public function getProviderOptions(array $config)
{
$options = [
'clientId' => $config['client_id'],
'clientSecret' => $config['client_secret'],
];

if ($config['issuer']) {
$options['issuer'] = $config['issuer'];
}

return $options;
}

public function getPackagistName()
{
return 'foxworth42/oauth2-okta';
}

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

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

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

0 comments on commit 8ede972

Please sign in to comment.