1212 * USAGE
1313 *
1414 * $app = new \Slim\Slim();
15- * $app->add(new \Slim\Extras\Middleware\StrongAuth(array('provider' => 'PDO', 'dsn ' => 'sqlite:memory')));
15+ * $app->add(new \Slim\Extras\Middleware\StrongAuth(array('provider' => 'PDO', 'pdo ' => new PDO( 'sqlite:memory') )));
1616 *
1717 * MIT LICENSE
1818 *
3939
4040class StrongAuth extends \Slim \Middleware
4141{
42- /**
43- * @var string
44- */
45- protected $ username ;
46-
47- /**
48- * @var string
49- */
50- protected $ password ;
51-
5242 /**
5343 * @var array
5444 */
5545 protected $ settings = array (
5646 'login.url ' => '/ ' ,
5747 'auth.type ' => 'http ' ,
48+ 'realm ' => 'Protected Area ' ,
5849 );
5950
6051 /**
6152 * Constructor
6253 *
6354 * @param array $config Configuration for Strong and Login Details
64- * @param \Strong $strong
55+ * @param \Strong\Strong $strong
6556 * @return void
6657 */
67- public function __construct (array $ config = array (), \Strong $ strong = null )
58+ public function __construct (array $ config = array (), \Strong \ Strong $ strong = null )
6859 {
6960 $ this ->config = array_merge ($ this ->settings , $ config );
70- $ this ->auth = (!empty ($ strong )) ? $ strong : \Strong::factory ($ this ->config );
61+ $ this ->auth = (!empty ($ strong )) ? $ strong : \Strong \Strong ::factory ($ this ->config );
7162 }
7263
7364 /**
@@ -82,26 +73,26 @@ public function call()
8273 // Authentication Initialised
8374 switch ($ this ->config ['auth.type ' ]) {
8475 case 'form ' :
85- $ this ->formauth ($ this ->auth , $ req );
76+ $ this ->formAuth ($ this ->auth , $ req );
8677 break ;
8778 default :
88- $ this ->httpauth ($ this ->auth , $ req );
79+ $ this ->httpAuth ($ this ->auth , $ req );
8980 break ;
9081 }
9182 }
9283
9384 /**
9485 * Form based authentication
9586 *
96- * @param \Strong $auth
87+ * @param \Strong\Strong $auth
9788 * @param object $req
9889 */
99- private function formauth ( \ Strong $ auth , $ req )
90+ private function formAuth ( $ auth , $ req )
10091 {
10192 $ app = $ this ->app ;
10293 $ config = $ this ->config ;
10394 $ this ->app ->hook ('slim.before.router ' , function () use ($ app , $ auth , $ req , $ config ) {
104- $ secured_urls = isset ($ config ['security.urls ' ]) ? $ config ['security.urls ' ] : array ();
95+ $ secured_urls = isset ($ config ['security.urls ' ]) && is_array ( $ config [ ' security.urls ' ]) ? $ config ['security.urls ' ] : array ();
10596 foreach ($ secured_urls as $ surl ) {
10697 $ patternAsRegex = $ surl ['path ' ];
10798 if (substr ($ surl ['path ' ], -1 ) === '/ ' ) {
@@ -129,10 +120,10 @@ private function formauth(\Strong $auth, $req)
129120 * the request has already authenticated, the next middleware is called. Otherwise,
130121 * a 401 Authentication Required response is returned to the client.
131122 *
132- * @param \Strong $auth
123+ * @param \Strong\Strong $auth
133124 * @param object $req
134125 */
135- private function httpauth ( \ Strong $ auth , $ req )
126+ private function httpAuth ( $ auth , $ req )
136127 {
137128 $ res = $ this ->app ->response ();
138129 $ authUser = $ req ->headers ('PHP_AUTH_USER ' );
0 commit comments