klarna-incubator / gram

Gram is Klarna's own threat model diagramming tool
Apache License 2.0
270 stars 12 forks source link

Failed to send notification, Error Code: undefined #64

Open vsmart-duo opened 10 months ago

vsmart-duo commented 10 months ago

Hey @Tethik and team! Very exciting that Gram is open source now πŸ™Œ

I tried following the Getting Started guide. The app started successfully but then I got stuck at the Login screen. When trying the "login via magic link" button, I got this error. I tried with 2 different email addresses:

[2023-11-07T14:28:04.172] [ERROR] NotificationSender - Failed to send notification 1: SMTP Error Code: undefined. See https://github.com/eleith/emailjs/blob/main/smtp/error.ts

Full error log here, emails and tokens redacted:

``` [2023-11-07T14:27:34.163] [DEBUG] NotificationSender - No new notifications to send [2023-11-07T14:27:54.570] [DEBUG] MagicLinkIdentityProvider - Sending magic link to with link http://localhost:4726/login/callback/magic-link?token= [2023-11-07T14:27:54.611] [DEBUG] NotificationDataService - Queued new mail magic-link - {"templateKey":"magic-link","params":{"link":"http://localhost:4726/login/callback/magic-link?token=","recipient":{"sub":"","to":"}}} [2023-11-07T14:27:54.613] [INFO] auditHttp - POST /api/v1/auth/token?provider=magic-link 44ms [2023-11-07T14:27:54.613] [DEBUG] auditHttp - body {"email":""} [2023-11-07T14:27:54.634] [INFO] auditHttp - GET /api/v1/user 0ms [2023-11-07T14:28:04.138] [DEBUG] wss - Number active channels: 0 [2023-11-07T14:28:04.172] [ERROR] NotificationSender - Failed to send notification 1: SMTP Error Code: undefined. See https://github.com/eleith/emailjs/blob/main/smtp/error.ts [2023-11-07T14:28:04.172] [WARN] NotificationSender - Failed to send notifications [1] [2023-11-07T14:28:34.138] [DEBUG] wss - Number active channels: 0 [2023-11-07T14:28:34.178] [DEBUG] NotificationSender - No new notifications to send [2023-11-07T14:29:04.139] [DEBUG] wss - Number active channels: 0 [2023-11-07T14:29:04.178] [DEBUG] NotificationSender - No new notifications to send [2023-11-07T14:29:12.229] [DEBUG] MagicLinkIdentityProvider - Sending magic link to with link http://localhost:4726/login/callback/magic-link?token= [2023-11-07T14:29:12.267] [DEBUG] NotificationDataService - Queued new mail magic-link - {"templateKey":"magic-link","params":{"link":"http://localhost:4726/login/callback/magic-link?token=","recipient":{"sub":"","to":""}}} [2023-11-07T14:29:12.268] [INFO] auditHttp - POST /api/v1/auth/token?provider=magic-link 39ms [2023-11-07T14:29:12.268] [DEBUG] auditHttp - body {"email":""} [2023-11-07T14:29:12.292] [INFO] auditHttp - GET /api/v1/user 3ms [2023-11-07T14:29:34.140] [DEBUG] wss - Number active channels: 0 [2023-11-07T14:29:34.183] [ERROR] NotificationSender - Failed to send notification 2: SMTP Error Code: undefined. See https://github.com/eleith/emailjs/blob/main/smtp/error.ts [2023-11-07T14:29:34.183] [WARN] NotificationSender - Failed to send notifications [2] [2023-11-07T14:30:04.141] [DEBUG] wss - Number active channels: 0 ```
Tethik commented 10 months ago

Hej @vsmart-duo - super excited to see you try it out :)

The error you see is likely due to SMTP not being able to send anything (I'm assuming here that it has no configuration at all).

The magic link is logged beforehand via debug, try clicking the link that's logged here:

[2023-11-07T14:29:12.229] [DEBUG] MagicLinkIdentityProvider - Sending magic link to <REDACTED> with link http://localhost:4726/login/callback/magic-link?token=<REDACTED>
Tethik commented 10 months ago

If using just the default configuration, you will also need to use one of the predefined user emails here: https://github.com/klarna-incubator/gram/blob/main/config/default.ts#L103-L119

    const sampleUsers: User[] = [
      {
        name: "User",
        sub: "user@localhost", // Must be the same as sub provided by IdentityProvider for authz to work
        mail: "user@localhost",
      },
      {
        name: "Reviewer",
        sub: "reviewer@localhost",
        mail: "reviewer@localhost",
      },
      {
        name: "Admin",
        sub: "admin@localhost",
        mail: "admin@localhost",
      },
    ];

Otherwise I believe the app will not permit you in due to authz issues - the app will attempt a user lookup on the email address, then fail if it doesn't find it.

βœ… Updated the QuickStart quickly to reflect this

vsmart-duo commented 10 months ago

yes, that worked! πŸŽ‰ First I tried clicking the link directly but as you expected it failed with "User not found" Then following the instructions in the second comment I was able to login with user@localhost πŸ‘

Tethik commented 10 months ago

Cool, let me know if you find any further issues. I think you're the first to actually try this out - so I appreciate the testing πŸ˜„