|
|
@@ -411,6 +411,8 @@ Authentication is handled on the system framework level by [`NSURLCredential` an
|
|
|
|
|
|
#### HTTP Basic Authentication
|
|
|
|
|
|
+The `authenticate` method on a `Request` will automatically provide an `NSURLCredential` to an `NSURLAuthenticationChallenge` when appropriate:
|
|
|
+
|
|
|
```swift
|
|
|
let user = "user"
|
|
|
let password = "password"
|
|
|
@@ -422,6 +424,23 @@ Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)")
|
|
|
}
|
|
|
```
|
|
|
|
|
|
+Depending upon your server implementation, an `Authorization` header may also be appropriate:
|
|
|
+
|
|
|
+```swift
|
|
|
+let user = "user"
|
|
|
+let password = "password"
|
|
|
+
|
|
|
+let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)!
|
|
|
+let base64Credentials = credentialData.base64EncodedStringWithOptions(nil)
|
|
|
+
|
|
|
+let headers = ["Authorization": "Basic \(base64Credentials)"]
|
|
|
+
|
|
|
+Alamofire.request(.GET, "http://httpbin.org/basic-auth/user/password", headers: headers)
|
|
|
+ .responseJSON { _, _, JSON, _ in
|
|
|
+ println(JSON)
|
|
|
+ }
|
|
|
+```
|
|
|
+
|
|
|
#### Authentication with NSURLCredential
|
|
|
|
|
|
```swift
|