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

[Question] gin router api with goth #592

Open
ppodevlabs opened this issue Jan 6, 2025 · 1 comment
Open

[Question] gin router api with goth #592

ppodevlabs opened this issue Jan 6, 2025 · 1 comment

Comments

@ppodevlabs
Copy link

Hi there!

I’m working on an application which is composed by a frontend react SPA connected to Angolan backend using gin router with goth.

As this is the first time working on a frontend app, im wondering what is the best approach to handle authentication.

shall i use the frontend app to authenticate against any provider and then use goth to verify the tokens? Or let goth handle the authentication and provide to the frontend with the tokens.

thanks in advance

@zeitue
Copy link

zeitue commented Jan 22, 2025

I just finished implementing something similar a few weeks ago. Basically, you have the frontend call the backend to start the authentication. After that, you collect the token and continue from there as usual on the backend. The last step is to redirect from the backend to the frontend with a JWT.

  1. The user clicks button on frontend
  2. Button navigates to the backend let's say /api/v1/auth/google
  3. The user does the normal process
  4. Google in this case redirects to /api/v1/auth/google/callback
  5. You then store the Google token or do whatever you need to with it.
  6. Finally redirect back the frontend /auth/callback?token=JWT_TOKEN_STRING
  7. The frontend stores the token as a cookie or something and redirects the user to the desired location.

There are other ways to do this, but I did this for my implementation.

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

No branches or pull requests

2 participants