Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
CORS AWS API-Gateway con autenticación Angular2

mi AWS API-Gateway está configurado como Lambda Proxy. En Lambda agregué los siguientes encabezados:

 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': '*', 'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key'

Primero, everythink funciona bien con eso. Ahora agregué un autorizador con CognitoUserPool y obtengo el siguiente error:

 XMLHttpRequest cannot load https://xxx.eu-west-1.amazonaws.com/xxx/xxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401.

Creo que el problema es que con la autenticación, mi función Lambda no se invoca y, por lo tanto, no se establecieron encabezados. Llamo al punto final desde una aplicación Angular2 con

 const headers = new Headers(); headers.append('Authorization', 'authtoken'); http.get('address...', headers);

Pero creo que los encabezados no se configuraron/añadieron a la solicitud debido a cualquier razón CORS.

¿Alguien tiene una idea de cómo puedo solucionar esto?

PD: probé la función "Habilitar Cors" de API-Gateway pero no funciona.

Editar: también tengo un método de "OPCIONES" en Gateway con autenticación, que responde con los encabezados anteriores.

Saludos

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

¿Su función Lambda Proxy se asigna a ANY tipo de método HTTP? Si es así, es posible que esté intentando realizar la autenticación en la solicitud previa al vuelo ( OPTIONS ). Si este es el caso, intente asignar su función de proxy a POST , GET , etc. específicamente.

over 4 years ago · Santiago Trujillo Report

0

Encontré la solución del problema. No fue causado por API-Gateway. El problema era este código:

 const headers = new Headers(); headers.append('Authorization', 'authtoken'); http.get('address...', headers);

El "get" necesita un objeto "RequestOptions". Tiene que ser:

 const headers = new Headers(); headers.append('Authorization', 'authtoken'); const options = new RequestOptions({headers: headers}); http.get('address...', options);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!