Comments (6)
As the name suggests Authorization: Basic
header. From JavaScript console check what you are actually sending. Since 1.7.2 the $.ajax() method has username
and password
which you can use instead of building the header manually.
$.ajax({
username: root,
password: t00r
});
If console shows you are sending correct header then check that your PHP receives the values. For example if you are using FastCGI it you need the rewrite rules from documentation.
from slim-basic-auth.
Oh scrap that. The username
and password
parameters seem to be added to the url. Quick google search suggests building the header manually after all. Something like:
$.ajax({
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization",
"Basic " + encodeBase64(username + ":" + password));
}
});
from slim-basic-auth.
I'm not finding an encodeBase64 function. I substituted btoa as this works in most browsers including Firefox - the browser where I'm testing. I've tested this and all I'm getting is a an authentication popup in Firefox. When I enter the valid credentials I can view the page, but I need to pass these values in my script.
This is my jQuery code:
<script type="text/javascript">
var user = 'admin';
var password = 'password';
$( document ).ready(function() {
$.ajax({
type: 'GET',
url: 'https://api.oyfhitn.com/stores?callback=?',
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization",
"Basic " + btoa(user + ":" + password));
},
success: function(myResults) {
for(i in myResults) {
console.log(myResults[i]);
}
},
dataType: 'jsonp'
});
});
</script>
This is my Slim code:
$app = new \Slim\Slim();
$app->add(new \Slim\Extras\Middleware\JSONPMiddleware());
$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"users" => [
"admin" => "password"
]
]));
/**
* Default route and response for API
*/
$app->get('/', function() use($app) {
$app->response->setStatus(200);
echo "Welcome to my awesome API.";
});
from slim-basic-auth.
There is a jQuery ticket about jsonp and basic authentication. Maybe related?
from slim-basic-auth.
Yes, this was related to jsonp and basic authentication. I ended up switching back to json and using Access Control headers to disable CORS. This will only be a problem during testing. Thanks for all the help!
from slim-basic-auth.
Ok great! Glad you made it work.
from slim-basic-auth.
Related Issues (20)
- Access user/passwd from Authenticator within Slim route handler HOT 1
- Specify callback for the relaxed configuration parameter HOT 3
- Authenticator misinterpretation of "authorization" header HOT 5
- Ignore is not working as expected
- Accessing slim request/app from inside custom authenticator HOT 2
- Uncaught Error: Interface 'Psr\Http\Message\ResponseFactoryInterface' not found HOT 2
- HTTP_X_FORWARDED_PROTO HOT 1
- ignore list HOT 1
- After/Before Callbacks never called? HOT 3
- Class 'Tuupola\Middleware\HttpBasicAuthentication' not found HOT 32
- 401 error in postman HOT 3
- Interface ResponseFactoryInterface not found HOT 5
- Authentification error HOT 4
- Connecting over HTTP when I should not be able to HOT 1
- "final class" and CloudFlare proxification error HOT 1
- Why does local(HTTP) connection work but not online(HTTPS)? HOT 16
- Add request object back to the error handler. HOT 3
- Allow using any callable as a rule
- Do not assume callbacks are a closure
- Before & After Callbacks Never Triggered
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slim-basic-auth.