Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
breart committed Feb 25, 2019
2 parents 3ea67fa + 2d18e22 commit 9897278
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.3] - 2019-02-25

### Added
- Implemented keeping resolved IdP (`Saml2::getResolvedIdPKey()`)

## [1.1.2] - 2019-02-17

### Fixed
Expand All @@ -31,7 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Replaced underscores with dots in routes
- Minor refactoring, formatting

[Unreleased]: https://github.com/24Slides/laravel-saml2/compare/v1.1.1...HEAD
[1.1.2]: https://github.com/24Slides/laravel-saml2/compare/v1.1.1...v1.1.2
[1.1.1]: https://github.com/24Slides/laravel-saml2/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/24Slides/laravel-saml2/compare/1.0.0...v1.1.0
[Unreleased]: https://github.com/24Slides/laravel-saml2/compare/1.1.1...HEAD
[1.1.3]: https://github.com/24Slides/laravel-saml2/compare/1.1.2...1.1.3
[1.1.2]: https://github.com/24Slides/laravel-saml2/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/24Slides/laravel-saml2/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/24Slides/laravel-saml2/compare/1.0.0...1.1.0
31 changes: 30 additions & 1 deletion src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ class Auth
*/
protected $base;

/**
* The name of the resolved identity provider.
*
* @var string
*/
protected $resolvedIdPKey;

/**
* Auth constructor.
*
* @param OneLoginAuth $auth
* @param string $resolvedIdPKey
*/
public function __construct(OneLoginAuth $auth)
public function __construct(OneLoginAuth $auth, string $resolvedIdPKey = null)
{
$this->base = $auth;
$this->resolvedIdPKey = $resolvedIdPKey;
}

/**
Expand Down Expand Up @@ -211,4 +220,24 @@ public function getBase()
{
return $this->base;
}

/**
* Set an Identity Provider.
*
* @param string $key
*/
public function setResolvedIdPKey(string $key)
{
$this->resolvedIdPKey = $key;
}

/**
* Get an Identity Provider.
*
* @return string|null
*/
public function getResolvedIdPKey()
{
return $this->resolvedIdPKey;
}
}
37 changes: 33 additions & 4 deletions src/IdpResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class IdpResolver
*/
protected $referrer;

/**
* The last resolved Identity Provider.
*
* @var string
*/
protected $lastResolved;

/**
* IdpResolver constructor.
*
Expand All @@ -48,6 +55,8 @@ public function resolve()
}

if(strpos($config['url'], $this->referrer) !== false) {
$this->lastResolved = $key;

return $config;
}
}
Expand All @@ -56,18 +65,38 @@ public function resolve()
throw new \InvalidArgumentException('Default IdP is not defined');
}

$this->lastResolved = $this->defaultIdPKey();

return $default;
}

/**
* Get the default IdP.
* Get the latest resolved IdP's key.
*
* @return string
*/
public function getLastResolvedKey(): string
{
return $this->lastResolved;
}

/**
* Get the default IdP config.
*
* @return array|null
*/
protected function retrieveDefaultIdP()
{
return array_get($this->idpConfig,
array_get($this->idpConfig, 'default')
);
return array_get($this->idpConfig, $this->defaultIdPKey());
}

/**
* Get the default's IdP key.
*
* @return string|null
*/
protected function defaultIdPKey()
{
return array_get($this->idpConfig, 'default');
}
}
26 changes: 23 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
*/
protected $defer = false;

/**
* @var IdpResolver
*/
protected $idpResolver;

/**
* Bootstrap the application events.
*
Expand Down Expand Up @@ -69,7 +74,10 @@ public function register()
$this->registerAuthenticationHandler();

$this->app->singleton('Slides\Saml2\Auth', function ($app) {
return new \Slides\Saml2\Auth($app['OneLogin_Saml2_Auth']);
return new \Slides\Saml2\Auth(
$app['OneLogin_Saml2_Auth'],
$this->idpResolver->getLastResolvedKey()
);
});
}

Expand All @@ -86,8 +94,7 @@ protected function registerAuthenticationHandler()
$this->setConfigDefaultValues($config);

$oneLoginConfig = $config;
$oneLoginConfig['idp'] = (new IdpResolver($config['idp'], URL::previous()))
->resolve();
$oneLoginConfig['idp'] = $this->resolveIdentityProvider($config['idp']);

return new OneLoginAuth($this->normalizeConfigParameters($oneLoginConfig));
});
Expand Down Expand Up @@ -162,4 +169,17 @@ protected function setDefaultValue(&$var, $default)
$var = $default;
}
}

/**
* Resolve an Identity Provider.
*
* @param array $config The IdPs config.
*
* @return array
*/
protected function resolveIdentityProvider(array $config): array
{
return ($this->idpResolver = new IdpResolver($config, URL::previous()))
->resolve();
}
}

0 comments on commit 9897278

Please sign in to comment.