Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create /api/send HTTP POST Endpoint for Auth to Call #28

Closed
5 tasks done
nelsonic opened this issue Mar 24, 2020 · 3 comments
Closed
5 tasks done

Create /api/send HTTP POST Endpoint for Auth to Call #28

nelsonic opened this issue Mar 24, 2020 · 3 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Mar 24, 2020

The goal of having a separate email service dwyl/auth#39 is to simplify sending email as much as possible.
At present it is relatively easy to send an email via the aws-ses-lambda function, but it requires quite a few steps of setup and 3 AWS environment variables. We don't want anyone contributing to the App to have to follow those steps in order to get the App running on their localhost. We want them to be able to use a single DWYL_API_KEY environment variable which connects them to the auth and email services.

  • receive payload data:
    • email
    • name
    • template
  • JWT

In the context of the diagram below, we are building Step 3:

dwyl-app-services-diagram

From the perspective of the App, it doesn't (ever need to) know about the Email service.
Everything Email related happens in the background.

@nelsonic nelsonic self-assigned this Mar 24, 2020
@nelsonic nelsonic changed the title Create /send-email HTTP POST Endpoint that Other Apps can Call Create /send HTTP POST Endpoint for Auth to Call Mar 25, 2020
@nelsonic nelsonic changed the title Create /send HTTP POST Endpoint for Auth to Call Create /api/send HTTP POST Endpoint for Auth to Call Mar 26, 2020
nelsonic added a commit that referenced this issue Mar 26, 2020
@nelsonic
Copy link
Member Author

Valid JWT:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImVtYWlsIjoic3VjY2Vzc0BzaW11bGF0b3IuYW1hem9uc2VzLmNvbSIsImV4cCI6MTU4NTI1MzU2MiwiaWF0IjoxNTg1MjQ2MzYyLCJpc3MiOiJKb2tlbiIsImp0aSI6IjJudnVxYW5kbjdhNjFwbTdsczAwMDBxMSIsIm5hbWUiOiJTdXBlciBTdWNjZXNzZnVsIiwibmJmIjoxNTg1MjQ2MzYyLCJ0ZW1wbGF0ZSI6IndlbGNvbWUifQ.rZeABtUwYLGeXopq04gI0VfRBgBUjQQKjAnSG1hs8sQ

Curl Request localhost:

curl -X POST "http://localhost:4000/api/send"\
  -H "Content-Type: application/json"\
  -H "authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImVtYWlsIjoic3VjY2Vzc0BzaW11bGF0b3IuYW1hem9uc2VzLmNvbSIsImV4cCI6MTU4NTI1MzU2MiwiaWF0IjoxNTg1MjQ2MzYyLCJpc3MiOiJKb2tlbiIsImp0aSI6IjJudnVxYW5kbjdhNjFwbTdsczAwMDBxMSIsIm5hbWUiOiJTdXBlciBTdWNjZXNzZnVsIiwibmJmIjoxNTg1MjQ2MzYyLCJ0ZW1wbGF0ZSI6IndlbGNvbWUifQ.rZeABtUwYLGeXopq04gI0VfRBgBUjQQKjAnSG1hs8sQ"

Expect to see the following response:

{
  "aud": "Joken",
  "email": "[email protected]",
  "exp": 1585253562,
  "iat": 1585246362,
  "id": 120,
  "iss": "Joken",
  "jti": "2nvuqandn7a61pm7ls0000q1",
  "name": "Super Successful",
  "nbf": 1585246362,
  "status": "Pending",
  "template": "welcome"
}

@nelsonic
Copy link
Member Author

Test it on Heroku:

curl -X POST "https://dwylmail.herokuapp.com/api/send"\
  -H "Content-Type: application/json"\
  -H "authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJKb2tlbiIsImVtYWlsIjoic3VjY2Vzc0BzaW11bGF0b3IuYW1hem9uc2VzLmNvbSIsImV4cCI6MTU4NTI1MzU2MiwiaWF0IjoxNTg1MjQ2MzYyLCJpc3MiOiJKb2tlbiIsImp0aSI6IjJudnVxYW5kbjdhNjFwbTdsczAwMDBxMSIsIm5hbWUiOiJTdXBlciBTdWNjZXNzZnVsIiwibmJmIjoxNTg1MjQ2MzYyLCJ0ZW1wbGF0ZSI6IndlbGNvbWUifQ.rZeABtUwYLGeXopq04gI0VfRBgBUjQQKjAnSG1hs8sQ"

Response:

{
  "aud": "Joken",
  "email": "[email protected]",
  "exp": 1585253562,
  "iat": 1585246362,
  "id": 24,
  "iss": "Joken",
  "jti": "2nvuqandn7a61pm7ls0000q1",
  "name": "Super Successful",
  "nbf": 1585246362,
  "status": "Pending",
  "template": "welcome"
}

@nelsonic
Copy link
Member Author

Documentation added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant