Skip to content

Commit db606bc

Browse files
committed
Add Basic auth to read from config.yml file
Add Basic auth to read from config.yml file you can view example from src\BeSimple\SoapBundle\Resources\doc\soapclient\configuration.rst line BeSimple#18 onwards
1 parent f2a8a7e commit db606bc

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/BeSimple/SoapBundle/DependencyInjection/BeSimpleSoapExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ private function registerClientConfiguration(array $config, ContainerBuilder $co
9797
$defOptions[$key] = $options[$key];
9898
}
9999
}
100+
101+
$auth = $options['auth'];
102+
if((false !== $auth['type']) && ($auth['type'] === 'basic')) {
103+
$definition->addMethodCall('withBasicAuthentication', array(
104+
$auth['login'], $auth['password']
105+
));
106+
}
100107

101108
$proxy = $options['proxy'];
102109
if (false !== $proxy['host']) {

src/BeSimple/SoapBundle/DependencyInjection/Configuration.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ private function addClientSection(ArrayNodeDefinition $rootNode)
8282
->prototype('array')
8383
->children()
8484
->scalarNode('wsdl')->isRequired()->end()
85+
->arrayNode('auth')
86+
->info('auth configuration')
87+
->addDefaultsIfNotSet()
88+
->beforeNormalization()
89+
->ifTrue(function ($v) { return !is_array($v); })
90+
->then(function ($v) { return array('type' => null === $v ? false : $v); })
91+
->end()
92+
->children()
93+
->scalarNode('type')->defaultFalse()->end()
94+
->scalarNode('login')->defaultNull()->end()
95+
->scalarNode('password')->defaultNull()->end()
96+
->end()
97+
->end()
8598
->scalarNode('user_agent')->end()
8699
->scalarNode('cache_type')
87100
->validate()

src/BeSimple/SoapBundle/Resources/doc/soapclient/configuration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Configure your first client in your config file:
1414
DemoApi:
1515
# required
1616
wsdl: http://localhost/app_dev.php/ws/DemoApi?wsdl
17+
# (optional)
18+
auth:
19+
type: basic # need to define as basic
20+
login: my_http_auth_username
21+
password: my_http_auth_password
1722
1823
# classmap (optional)
1924
classmap:

0 commit comments

Comments
 (0)