iOS iOS - 1 year ago 105
Swift Question

Alamofire Invalidate credential

I'm using

to do a simple request

Alamofire.request(.GET, URL)
.authenticate(user: user, password: password)
.responseJSON { response in

After a first valid request, I changed the credential with invalid ones and the request succeed, but it should fail.

How can I invalidate previous credentials?

After a successful request, if I change the credential,
authenticates the previous credential.

How can I invalidate previous credentials?

Answer Source

Adding Authorization header helped me.

let user = "user"
let password = "password"

let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)!
let base64Credentials = credentialData.base64EncodedStringWithOptions([])

let headers = ["Authorization": "Basic \(base64Credentials)"]

Alamofire.request(.GET, "", headers: headers)
         .responseJSON { response in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download