---
title: "CFHTTPMessageApplyCredentials(_:_:_:_:_:)"
framework: cfnetwork
role: symbol
role_heading: Function
path: "cfnetwork/cfhttpmessageapplycredentials(_:_:_:_:_:)"
---

# CFHTTPMessageApplyCredentials(_:_:_:_:_:)

Performs the authentication method specified by a CFHTTPAuthentication object.

## Declaration

```swift
func CFHTTPMessageApplyCredentials(_ request: CFHTTPMessage, _ auth: CFHTTPAuthentication, _ username: CFString?, _ password: CFString?, _ error: UnsafeMutablePointer<CFStreamError>?) -> Bool
```

## Parameters

- `request`: Request for which the authentication method is to be performed.
- `auth`: A CFHTTPAuthentication object specifying the authentication method to perform.
- `username`: Username for performing the authentication.
- `password`: Password for performing the authentication.
- `error`: If an error occurs, upon return contains a doc://com.apple.documentation/documentation/CoreFoundation/CFStreamError object that describes the error and the error’s domain. Pass NULL if you don’t want to receive error information.

## Return Value

Return Value TRUE if the authentication was successful, otherwise, FALSE.

## Discussion

Discussion This function performs the authentication method specified by auth on behalf of the request specified by request using the credentials specified by username and password. If, in addition to a username and password, you also need to specify an account domain, call CFHTTPMessageApplyCredentialDictionary(_:_:_:_:) instead of this function. This function is appropriate for performing several authentication requests. If you only need to make a single authentication request, consider using CFHTTPMessageAddAuthentication(_:_:_:_:_:_:) instead. Special Considerations This function is thread safe as long as another thread does not alter the same CFHTTPMessage object at the same time.

## See Also

### HTTP Messages

- [CFHTTPMessage](cfnetwork/cfhttpmessage.md)
- [CFHTTPMessageAddAuthentication(_:_:_:_:_:_:)](cfnetwork/cfhttpmessageaddauthentication(_:_:_:_:_:_:).md)
- [CFHTTPMessageAppendBytes(_:_:_:)](cfnetwork/cfhttpmessageappendbytes(_:_:_:).md)
- [CFHTTPMessageApplyCredentialDictionary(_:_:_:_:)](cfnetwork/cfhttpmessageapplycredentialdictionary(_:_:_:_:).md)
- [CFHTTPMessageCopyAllHeaderFields(_:)](cfnetwork/cfhttpmessagecopyallheaderfields(_:).md)
- [CFHTTPMessageCopyBody(_:)](cfnetwork/cfhttpmessagecopybody(_:).md)
- [CFHTTPMessageCopyHeaderFieldValue(_:_:)](cfnetwork/cfhttpmessagecopyheaderfieldvalue(_:_:).md)
- [CFHTTPMessageCopyRequestMethod(_:)](cfnetwork/cfhttpmessagecopyrequestmethod(_:).md)
- [CFHTTPMessageCopyRequestURL(_:)](cfnetwork/cfhttpmessagecopyrequesturl(_:).md)
- [CFHTTPMessageCopyResponseStatusLine(_:)](cfnetwork/cfhttpmessagecopyresponsestatusline(_:).md)
- [CFHTTPMessageCopySerializedMessage(_:)](cfnetwork/cfhttpmessagecopyserializedmessage(_:).md)
- [CFHTTPMessageCopyVersion(_:)](cfnetwork/cfhttpmessagecopyversion(_:).md)
- [CFHTTPMessageCreateCopy(_:_:)](cfnetwork/cfhttpmessagecreatecopy(_:_:).md)
- [CFHTTPMessageCreateEmpty(_:_:)](cfnetwork/cfhttpmessagecreateempty(_:_:).md)
- [CFHTTPMessageCreateRequest(_:_:_:_:)](cfnetwork/cfhttpmessagecreaterequest(_:_:_:_:).md)
