0
votes

I am struggling to authenticate using a POST request to an API.

Documentation says that I need to pass in "Request Headers: Content-Type: application/x-www-form-urlencoded, Request Body: client_id=CLIENT_ID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN." I cannot get it to work on the iOS app however trying with Postman works fine.

 let headers: HTTPHeaders = [
        "Contenty-Type": "application/x-www-form-urlencoded"
    ]
    
    let params = [
    "client_id": "123",
    "refresh_token": "123"
    ]
    
    private func getAccess() {
        Alamofire.request(getRequest ,method: .post, parameters: params, headers: headers)
            .responseJSON { (response) in

            switch response.result {
            
            case .success(let json):
                print(json)
                DispatchQueue.main.async {
               }
                
            case .failure(let error):
                print(error)
            }
    }
1

1 Answers

0
votes

You are not passing grant_type parameter. Try changing your params dictionary to this:

let params = [
    "client_id": "123",
    "grant_type": "refresh_token",
    "refresh_token": "123"
]