0

I have this :

curl https://address --user appID:appKey -d grant_type=password -d scope=read -d format=json -d username="username" -d password="password"

and I try to convert it in swift. Can you help me please?

There is no link between the username and the password and the appId and the appKey

I already have that :

private func LoadKey() {
    var params : [String:String] = ["grant_type":"password",
                                    "scope":"read",
                                    "format":"json",
                                    "username":"myUsername",
                                    "password":"myPassword"]

    Alamofire.request(url, method: .post, encoding: JSONEncoding.default).responseJSON { (response) in
        print(response.result.value)
    }   
}

and I have no idea about how give the appId and appKey

Thank you in advance for your answer and have a good day.

Dusart Victor
  • 76
  • 3
  • 11
  • 1
    What have you tried so far? – mag_zbc Feb 25 '19 at 14:26
  • I update my post – Dusart Victor Feb 25 '19 at 14:41
  • You can use a tip I gave there: https://stackoverflow.com/questions/53637437/alamofire-with-d/53637821#53637821 to understand what parameter to put in the Alamofire Request construction. You'll see then (and you didn't give it) that's it's missing the --user param, so Alamofire + --user gives: https://stackoverflow.com/questions/31434008/entering-username-and-password-for-alamofire-request – Larme Feb 25 '19 at 21:11

1 Answers1

0

Since the curl command doesn't specify an authentication type I assume it's basic authentication. If so please try the following:

private func LoadKey() {
    var params : [String:String] = ["grant_type":"password",
                                    "scope":"read",
                                    "format":"json",
                                    "username":"myUsername",
                                    "password":"myPassword"]

    Alamofire.request(url, method: .post, encoding: JSONEncoding.default)
                    .authenticate(user: "appID", password: "appKey")
                    .responseJSON { (response) in
                print(response)
            } 
}

Best, Carsten

carsten
  • 248
  • 2
  • 8