Repository navigation
Description
Apple platform
iOS
Framework version
net10.0-*
Affected platform version
net10.0-ios / Microsoft.iOS.Sdk 26.5.10280
Description
I am seeing an authentication negotiation issue on iOS when using NSUrlSessionHandler with Credentials = new NetworkCredential(...).
The server responds to an unauthenticated PROPFIND with multiple WWW-Authenticate challenges, in this order:
WWW-Authenticate: Bearer realm="example.com", charset="UTF-8"
WWW-Authenticate: Basic realm="example.com", charset="UTF-8"
curl --anyauth handles this by retrying with Basic auth and receives the expected authenticated response.
With NSUrlSessionHandler, the credentials-only request remains unauthenticated and returns 401 Unauthorized. In the same repro app, manually setting the Basic authorization header on the request succeeds and returns the expected authenticated response.
I attached a minimal repro project. It includes:
- a .NET mock server that returns
WWW-Authenticate: Bearerfirst andBasicsecond - a minimal .NET iOS app using
NSUrlSessionHandler - a second button showing that manually setting
Authorization: Basic ...works run-repro.command, which starts the mock server, builds the iOS app, installs it into the simulator, and launches it
This looks similar in spirit to NSUrlSessionHandler - basic auth and multiple auth headers #5052, but with Bearer before Basic.
Steps to Reproduce
- Extract the attached repro: nsurlsessionhandler-auth-repro.zip
- On macOS, double-click or run:
./run-repro.commandThis starts the mock server, builds the iOS app, boots the first available iPhone simulator, installs the app, and launches it.
3. In the iOS app, tap Test NSUrlSessionHandler.Credentials.
4. Compare with Test manual Basic Authorization header.
5. Optional: verify the server behavior separately with curl:
curl -v --anyauth -u "admin:comic bluish relish eloquent pungent snowplow" -X PROPFIND -H "Depth: 1" "http://127.0.0.1:8787/remote.php/dav/spaces/test/example-resource"Expected:
NSUrlSessionHandler.Credentials should use the advertised Basic challenge and retry with Basic credentials, returning the authenticated response (404 Not Found in this repro, because the requested WebDAV resource does not exist).
Actual:
The credentials-only path returns 401 Unauthorized.
The manual Basic-header path returns 404 Not Found, proving that the same credentials and endpoint work when the Basic header is sent explicitly.
Did you find any workaround?
Manually set the Basic auth header on the request:
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")));This avoids challenge negotiation and works against the affected endpoint.
Relevant logs
Credentials-only path:
PROPFIND /remote.php/dav/spaces/test/example-resource
Depth: 1
Authorization: (none)
=> 401 with Bearer first, Basic second
Manual Basic-header path:
PROPFIND /remote.php/dav/spaces/test/example-resource
Depth: 1
Authorization: Basic [redacted]
=> 404 authenticated
Server challenge:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mock-webdav", charset="UTF-8"
WWW-Authenticate: Basic realm="mock-webdav", charset="UTF-8"
curl also retries successfully:
Authorization: Basic [redacted]
HTTP/1.1 404 Not Found
Activity
rolfbjarne commentedon May 21, 2026
Thanks for the report!
I'll have a look and see what we can do.
[NSUrlSessionHandler] Reject unsupported auth methods to allow fallba…