-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Slim] Add Basic authentication middleware #606
[Slim] Add Basic authentication middleware #606
Conversation
At the last moment I've found slim-basic-auth package.
|
@wing328 @ackintosh One more thing. If we use 3rd party package then user have only settings without access to middleware source files. I'm still thinking what approach I should use. |
Normally users shouldn't need to modify the source code of slim-basic-auth (or other PHP libs). If slim-basic-auth fails to meet their requirement somehow, I would suggest opening an issue instead as slim-basic-auth is pretty active and likely the owners of slim-basic-auth can address that. Here are my feedback (although I've not played with
|
User needs to add own implementation to verifyCredentials method in AuthBasic.php.
I'm not sure about `middlewareSrcPath` variable. I'll fix it in following PRs if path is broken. Hope that notice in README catches attention and most of users will read it.
This reverts commit 204ee02.
This reverts commit 6a8e030.
Package "tuupola/slim-basic-auth" 3.1.0 requires PHP 7, that's why I set it's version to ^3.0.0 in Composer. Minimum version will be 3.0.0-rc.1 which supports PHP 5.5. I've tested build with PHP 7, it would be nice to check build with PHP 5.5 someday.
Not sure about forward slash in path to SlimRouter class. I will fix it in upcoming PRs if necessary.
d0132c6
to
af5f30b
Compare
I can remove revert commits and wipe off custom implementation from history if needed. |
<directory suffix=".php">./lib/Api</directory> | ||
<directory suffix=".php">./lib/Model</directory> | ||
<directory suffix=".php">./lib//Api</directory> | ||
<directory suffix=".php">./lib//Model</directory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ybelenko I believe the double forward slash won't cause any issue. Please correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, and what are benefits from double forward slash, may I ask? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I do not know. I spotted the double forward slash and just asking to make sure phpunit still works fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked on Win8.1, phpunit works fine. These slash changes is result of #610 . I just use {{apiSrcPath}}
and {{modelSrcPath}}
which defined in AbstractPhpCodegen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
This PR breaks the Shippable CI build => ensure-up-to-date |
@jmini Sad to hear it. Any ideas what's wrong and how to fix it? |
* [Slim] Add Basic Authentication Middleware User needs to add own implementation to verifyCredentials method in AuthBasic.php. * [Slim] Update README template I'm not sure about `middlewareSrcPath` variable. I'll fix it in following PRs if path is broken. Hope that notice in README catches attention and most of users will read it. * Revert "[Slim] Update README template" This reverts commit 204ee02. * Revert "[Slim] Add Basic Authentication Middleware" This reverts commit 6a8e030. * [Slim] Add "tuupola/slim-basic-auth" package Package "tuupola/slim-basic-auth" 3.1.0 requires PHP 7, that's why I set it's version to ^3.0.0 in Composer. Minimum version will be 3.0.0-rc.1 which supports PHP 5.5. I've tested build with PHP 7, it would be nice to check build with PHP 5.5 someday. * [Slim] Update README template Not sure about forward slash in path to SlimRouter class. I will fix it in upcoming PRs if necessary. * [Slim] Refresh samples
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.1.x
,4.0.x
. Default:master
.Description of the PR
Basic auth middleware verifies token from
Authorization
header.If token not verified it returns
401
http status code and quits script execution.User needs to implementMy code swapped with tuupola/slim-basic-auth package.verifyCredentials
method inAuthBasic.php
. By default this method always returnsfalse
to avoid security holes on production.For a quick start, user needs to implement own
authenticator
inSlimRouter
class:Test endpoint with Basic auth:
Output:
HTTP/1.1 401 Unauthorized Date: Tue, 24 Jul 2018 08:54:42 GMT Server: Apache/2.4.23 (Win64) PHP/7.2.7 X-Powered-By: PHP/7.2.7 WWW-Authenticate: Basic realm="Protected" Content-Length: 0
cc @jebentier @dkarlovi @mandrean @jfastnacht @ackintosh