<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CFNetwork",
  "identifier" : "/documentation/CFNetwork/CFHTTPAuthenticationCreateFromResponse(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFHTTPAuthenticationCreateFromResponse"
  },
  "title" : "CFHTTPAuthenticationCreateFromResponse(_:_:)"
}
-->

# CFHTTPAuthenticationCreateFromResponse(_:_:)

Uses an authentication failure response to create a CFHTTPAuthentication object.

```
func CFHTTPAuthenticationCreateFromResponse(_ alloc: CFAllocator?, _ response: CFHTTPMessage) -> Unmanaged<CFHTTPAuthentication>
```

## Parameters

`alloc`

The allocator to use to allocate memory for the new object. Pass `NULL` or kCFAllocatorDefault to use the current default allocator.

`response`

Response indicating an authentication failure; usually a 401 or a 407 response.

## Return Value

CFHTTPAuthentication object that can be used for adding credentials to future requests. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

This function uses a response containing authentication failure information to create a reference to a CFHTTPAuthentication object. You can use the object to add credentials to future requests. You can query the object to get the following information:

- whether it can be used and re-used to authenticate with its corresponding server [[`CFHTTPAuthenticationIsValid(_:_:)`](/documentation/CFNetwork/CFHTTPAuthenticationIsValid(_:_:))]
- the authentication method that will be used when it is used to perform an authentication [[`CFHTTPAuthenticationCopyMethod(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationCopyMethod(_:))]
- whether it is associated with a particular CFHTTPMessageRef [[`CFHTTPAuthenticationAppliesToRequest(_:_:)`](/documentation/CFNetwork/CFHTTPAuthenticationAppliesToRequest(_:_:))
- whether a user name and a password will be required when it is used to perform an authentication [[`CFHTTPAuthenticationRequiresUserNameAndPassword(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationRequiresUserNameAndPassword(_:))]
- whether an account domain will be required when it is used to perform an authentication [[`CFHTTPAuthenticationRequiresAccountDomain(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationRequiresAccountDomain(_:))]
- whether authentication requests should be sent one at a time to the corresponding server [[`CFHTTPAuthenticationRequiresOrderedRequests(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationRequiresOrderedRequests(_:))]
- the namespace (if any) that the domain uses to prompt for a name and password [[`CFHTTPAuthenticationCopyRealm(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationCopyRealm(_:))]
- the domain URLs the instance applies to [[`CFHTTPAuthenticationCopyDomains(_:)`](/documentation/CFNetwork/CFHTTPAuthenticationCopyDomains(_:))]

When you have determined what information will be needed to perform the authentication and accumulated that information, call [`CFHTTPMessageApplyCredentials(_:_:_:_:_:)`](/documentation/CFNetwork/CFHTTPMessageApplyCredentials(_:_:_:_:_:)) or [`CFHTTPMessageApplyCredentialDictionary(_:_:_:_:)`](/documentation/CFNetwork/CFHTTPMessageApplyCredentialDictionary(_:_:_:_:)) to perform the authentication.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)