How to provide frontend with JSON web token after server authentication?

前端 未结 4 598
南旧
南旧 2021-02-04 04:57

So far I have only dealt with server-rendered apps, where after a user logs in via username/password or using an OAuth provider (Facebook etc.), the server just sets a session c

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 05:34

    1. Client: Open a popup window via $auth.authenticate('provider name').
    2. Client: Sign in with that provider, if necessary, then authorize the application.
    3. Client: After successful authorization, the popup is redirected back to your app, e.g. http://localhost:3000, with the code (authorization code) query string parameter.
    4. Client: The code parameter is sent back to the parent window that opened the popup.
    5. Client: Parent window closes the popup and sends a POST request to /auth/provider withcode parameter.
    6. Server: Authorization code is exchanged for access token.
    7. Server: User information is retrived using the access token from Step 6.
    8. Server: Look up the user by their unique Provider ID. If user already exists, grab the existing user, otherwise create a new user account.
    9. Server: In both cases of Step 8, create a JSON Web Token and send it back to the client.
    10. Client: Parse the token and save it to Local Storage for subsequent use after page reload.

      Log out

    11. Client: Remove token from Local Storage

提交回复
热议问题