Problem with Swift API Gateway key authorizatiion Ask

0 votes

I tried adding a key for my API but there's a problem with implementing it into my application's code. 
I keep on getting a message = Forbidden;

I tried different methods but none of them seems to be working. 
I can't really figure out the problem here!

if let jsonData = try? JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted) {

        let url = NSURL(string: "\(APIAddress)")!
        let request = NSMutableURLRequest(url: url as URL)

        request.httpMethod = "PATCH"
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        request.addValue("\(APIKey)", forHTTPHeaderField: "Authorization")
        request.httpBody = jsonData

        let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
            if error != nil {
                print(error?.localizedDescription as Any)
                return
            }

            do {
                let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary

                if let parseJSON = json {
                    let resultValue = parseJSON["success"]
                    print("result: \(String(describing: resultValue))")
                    print(parseJSON)
                }
            } catch let error as NSError {
                print(error)
            }
        }
        task.resume()
    }

Please note the method was working before activating the API key on API Gateway

Jun 12, 2018 in AWS by Luke cage
• 360 points
763 views

1 answer to this question.

0 votes

Try to add all the headers that are required for the request.

You can check these documents for the requests to be added: https://docs.aws.amazon.com/apigateway/api-reference/making-http-requests/

Looks like you didn't add the host and x-amz-date headers.

answered Jun 12, 2018 by Cloud gunner
• 4,670 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

Using an API Gateway in conjunction with microservices and JWTs?

This is how we went about it... What ...READ MORE

answered Oct 17, 2018 in AWS by Priyaj
• 58,100 points
1,587 views
+1 vote
3 answers
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,653 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,935 views
0 votes
2 answers
+1 vote
2 answers

Starting with an AWS Instance with API and AUTHPARAMS

The API is usually much easier to ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,670 points
3,756 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP