amazon-archives / aws-cognito-angular-quickstart

An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
https://cognito.budilov.com
Apache License 2.0
689 stars 304 forks source link

Sending the authentication details to node js Serverless API #153

Open khaledshamat opened 5 years ago

khaledshamat commented 5 years ago

First of all, I would like to thank you for the great implementation, its very easy to play around with it and its readable, so I wanted to add some extra function to make a request to my secured Serverless API, which has the following configurations in the Serverless.yml file: ` functions: get:

Defines an HTTP API endpoint that calls the main function in get.js

# - path: url path is /orders/{id}
# - method: GET request
handler: src/orders/get.main
events:
  - http:
      path: orders/{id}
      method: get
      cors: true
      authorizer: aws_iam

`

but every time the request is sent I get the following on my api cloud watch logs:

error: Object message: "Missing Authentication Token"

Any advice please?

mordka commented 5 years ago

You need to sign all API requests using sigv4. You can use amplify to do that https://aws-amplify.github.io/amplify-js/ Note, this repo was created before Amplify Cognito support. I would not use it as of 2019.

tillkuhn commented 5 years ago

@mordka Thanks for your hint. I actually also forked this project some time ago to build an application around it, but now heard multiple times it's no longer the recommended way to use Cognito in client side code. Can you recommend a similar Angular project based on Amplify that would will the gap and already and already covers a basic use cases? Sure, the docs are comprehensive, but some may not want to start from scratch, myself included :-)

mordka commented 5 years ago

I can't recommend any good bootstrapping project in Amplify. There are some resources here: https://github.com/dabit3/awesome-aws-amplify but you can see Angular is not popular. I would recommend starting from scratch for deeper understanding of the underlying services. From my experience working with Amplify is not a seamless experience, mainly because their team tries to catch many birds with one shot.

fzhangj2ee commented 5 years ago

@tillkuhn. Can you please provide any links why "it's no longer the recommended way to use Cognito in client side code.", is it because of Amplify?

tillkuhn commented 5 years ago

@fzhangj2ee I was more referring to this particular project, see also Issue 149 ! The project really keeps up its promise of giving you a "quick start", but it seem to be no longer actively maintained and I was feeling exactly the same as @mordka when I tried to customize my fork and keep it up to date with recent angular versions. I'm not blaming the author as it probably was just meant to be sample app. Maybe @mordka can elaborate further on this as I just realized it’s the same person who commented on the current issue here, also note I have no prior experience with Amplify but it’s now on my list of things to evaluate :-)

tillkuhn commented 5 years ago

Update for those who try to evaluate Amplify Cognito within a fresh Angular Project: This nice tutorial should get you started quickly and shows you how to overcome some common pitfalls.