0

I am unable to log in as an authenticated user to Drupal services. I have tried the setting for 'basic authentication', for 'http authentication', and for no authentication, it seems to make no difference. I am using administrator login details. Same result for authenticated user login details. I am able to return data eg votes where anonymous user access is permitted. I can log in to services as an authenticated user when I directly try it on the site eg example.com/ios1/user/1 . But with my Xcode7 swift2 api, every time my drupal log shows that I've connected as an anonymous user only. So when I try a GET query for user details (requiring authentication) it returns access denied. What code header do I need?

This is what I've been using:

    let user = "exampleName"
    let password = "examplePass"

    let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)!
    let base64Credentials = credentialData.base64EncodedStringWithOptions([])
    let headers = ["Content-Type : application/json"]
Dimitri T
  • 921
  • 1
  • 13
  • 27

1 Answers1

0

solved. In Drupal services I selected 'http basic authentication' and had to change the headers to this, plus add 'headers:headers' in to the alamofire request, as such:

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

    //instead if this: let headers = ["Content-Type : application/json"]

and the Alamofire request is;

    Alamofire.request(.GET, Endpoint, parameters: nil, headers: headers, encoding: .JSON)
        .response { request, response, data, error in
            debugPrint(response)
            print(request)
            print (response)
            print (error)
Dimitri T
  • 921
  • 1
  • 13
  • 27