Search code examples
reactjsscalaplaybacksilhouette

Silhouette - react + scala + play app authentication flow


I need to create basic app with a silhouette. What I need to do is:

  • login with Google
  • Generate JWT
  • Use JWT to communicate with backend

I don't really know how this flow should look like. My idea is:

  • use login with Google in react app
  • generate Google token
  • use this token to generate JWT in the backend (using silhouette)
  • retrieve JWT in frontend

Will that flow work? Is there any simpler/better way to do that?


Solution

  • I had similar problem, so that's my proposal:

    1. Create a controller for social authentication on backend side.
    2. In react app add button for authentication and simply redirect to the backend endpoint.
    3. Authenticate user on backend, use Silhouette JWTAuthenticator to create a JWT token
    4. Redirect to the react app with JWT token in query params.
    5. Save token and use it in consequtive requests