Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from juliardi/master
Browse files Browse the repository at this point in the history
Allow set config from array
  • Loading branch information
asasmoyo authored May 19, 2018
2 parents 9abde1c + 67518cf commit 4d4150c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ language: php
php:
- '5.6'
- '7.0'
- hhvm

install:
- composer install
- composer update

script: phpunit --verbose --debug --bootstrap tests/bootstrap.php tests
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,52 @@ return [
];
```

**NOTE : As of version 1.6.0 you can directly put your configuration into your component. For example:**

```php
<?php

$urlManager = Yii::$app->urlManager;
$spBaseUrl = $urlManager->getHostInfo() . $urlManager->getBaseUrl();

$config = [
// some other configuration here

'components' => [
'saml' => [
'class' => 'asasmoyo\yii2saml\Saml',
'config' => [
'sp' => [
'entityId' => $spBaseUrl.'/saml/metadata',
'assertionConsumerService' => [
'url' => $spBaseUrl.'/saml/acs',
],
'singleLogoutService' => [
'url' => $spBaseUrl.'/saml/sls',
],
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
],
'idp' => [
'entityId' => 'identity-provider',
'singleSignOnService' => [
'url' => 'https://idp.com/sso',
],
'singleLogoutService' => [
'url' => 'https://idp.com/sls',
],
'x509cert' => '<x509cert string>',
],
];
]
],

// some other configuration here
];

return $config;

```

Usage
-----

Expand Down Expand Up @@ -207,7 +253,7 @@ Usage
-----

If the SAMLResponse is rejected, add to the SAML settings the parameter
```
```
'debug' => true,
```
and the reason will be prompted.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"onelogin/php-saml": "~2.13.0"
},
"require-dev": {
"phpunit/phpunit": "5.1.*"
"phpunit/phpunit": "5.0.*"
},
"autoload": {
"psr-4": {
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/Saml.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ class Saml extends BaseObject
* Configurations for OneLogin_Saml2_Auth.
* @var array
*/
private $config;
public $config;

public function init()
{
parent::init();

$configFile = Yii::getAlias($this->configFileName);
if (empty($this->config)) {
$configFile = Yii::getAlias($this->configFileName);
$this->config = require($configFile);
}

$this->config = require($configFile);
$this->instance = new \OneLogin_Saml2_Auth($this->config);
}

Expand Down Expand Up @@ -99,7 +101,7 @@ public function processResponse()

public function processSLO()
{
$this->instance->processSLO();
$this->instance->processSLO();
}

/**
Expand Down
12 changes: 11 additions & 1 deletion tests/SamlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@

class SamlTest extends \PHPUnit_Framework_TestCase
{

public function testCreateInstance()
{
$instance = new Saml();
$this->assertNotEquals($instance, null);
}

public function testConfigFromArray()
{
$config = require __DIR__ . '/config/saml.php';

$instance = new Saml([
'config' => $config,
]);

$this->assertNotEquals($instance->config, []);
$this->assertEquals($instance->config['sp']['entityId'], 'service-provider');
}
}

0 comments on commit 4d4150c

Please sign in to comment.