DEV Community

JWT authentication in an Angular application with a Go backend

Nikola Brežnjak on February 19, 2018

Originally published on my blog. TL;DR In this tutorial, I'm going to show you how to build a simple web app that handles authenticat...
Collapse
 
dadoerigext profile image
dadoerigext

Thanks a lot for this tutorial! I am just going through it. There is a small typo in the go sample for generating the verification signature. The variable on the last line should be 'b' instead of 'a'.

Collapse
 
nikola profile image
Nikola Brežnjak

Thank you, I'm glad it was useful to you!

Thanks for the heads up, I updated the post 👍

Collapse
 
gnyblast profile image
Güney Saramali

Hey, first of all, thanks for your nice post about this topic which is one of the cleanest article on the internet about GoLang + Angular auth. But theres one stuff I'd like to ask. If I set localStorage.setItem('token','something') then I'll have access to the auth reqiured page on the front-end right? Ok the GoLang back-end still verifies the JWT token and won't return any database related or If you using the GoLang back-end as a file server maybe, it won't return any file but still I'll be able to get into the auth required front-end page and see some content that is getting generated by Angular right? Because CanActivateViaAuthGuard looks for isAuthenticated and isAuthenticated is just looking for the localStorage item is set or not. Am I true in this point of view or do I miss something?

Collapse
 
sergioprats1 profile image
Sergio Prats López

I think the func account should be spliting by points and not by spaces at
authArr := strings.Split(authToken, " ")
Also, I believe the expected value for len(authArr) should be 3.

Collapse
 
alialhajji profile image
Ali Alhajji

This was really helpful and informative. I like how you care about explaining the little details. Thank you!

Collapse
 
nikola profile image
Nikola Brežnjak

Hey Ali,

Thank you, I'm so glad this was helpful!

Collapse
 
rubenfrontend profile image
rubenfrontend

I would like to implement a refresh token, that active when the token finished,
I think that I should include in the AuthInterceptorService. Thank you very much in advance.