-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[BUG] HTTP authentication doesn't work #14067
Comments
Playwright will only add the basic auth when the response of the initial request was a |
@mxschmitt I am just starting out with Playwright and have hit this issue. From what you are saying, Playwright is expecting a "challenge" response from the server, after which it will resend the request with the In my situation, I don't get that. It seems that the server that I'm using for API testing expects the If I don't manually insert the header, when Playwright makes the request, the server responds with "403 Forbidden". |
I have just read the RFC7617 specification and, interestingly, it says that the server can respond with a 401 status code, not that it will or must respond with that status code:
Additionally, it seems to be saying that the challenge response would be sent only if the server receives "a request for a URI within the protection space that lacks credentials". So the challenge should only be issued if the credentials weren't provided in the first place. Given that the server is not required to send a 401 response if the credentials are missing (and indeed, the server that I'm testing against does not), would it make more sense for Playwright to simply include the credentials in the original request? I think where I (and possibly @ivan-freedomfi) tripped up is that I assumed that adding the This behaviour is also somewhat opaque to somebody reading the Playwright documentation. What I have noted, since discovering the "workaround" above, is that the "workaround" is actually the "solution". It's alluded-to in the documentation here with this piece of code: // playwright.config.ts
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
// All requests we send go to this API endpoint.
baseURL: 'https://api.github.com',
extraHTTPHeaders: {
// We set this header per GitHub guidelines.
'Accept': 'application/vnd.github.v3+json',
// Add authorization token to all requests.
// Assuming personal access token available in the environment.
'Authorization': `token ${process.env.API_TOKEN}`,
},
}
};
export default config; But in the "basic auth" case, we don't need the I struggled with all this because initially I was reading the guide for authentication, which had a note:
The trouble I had was that there was no context or examples given, so it wasn't all that helpful. Now that I've put all the pieces together, it finally makes sense! |
In #16005 I have a reproduction where the httpCredentials are not being sent even though the server is responding with a 401. |
I agree with this opinion as well. If I went to the bother of creating a new browser context so that I could specify |
Playwright 1.45 has just been released, with an |
Context:
[email protected]
npx envinfo --preset playwright --markdown
System:
Binaries:
Languages:
npmPackages:
Code Snippet
Output (no
Authorization
header):Describe the bug
Passing
httpCredentials
torequest.newContext()
doesn't work: the requests are still not authorized (noAuthentication
header) - see output above.But if I do it manually like below, it works:
Output of manual adding of
Authorization
: the header is present:The text was updated successfully, but these errors were encountered: