So far my website has been using fullstack views generated directly by Rails, and for linkedin authentication I used a redirect_uri routed to a Devise::OmniauthCallbacksController
to handle the logic.
GET https://www.linkedin.com/oauth/v2/authorization?redirect_uri=my_devise_omniauth_callback_url
I am wondering how to migrate this to a standalone React frontend + a standalone Rails server. The React app should "spawn" a linkedin popup for authorization, and wait until all the authorization process is done before closing itself and proceeding with registration on the main window.
I have been through the Linkedin OAuth guide and I see the way from approving the connection to getting user info is quite long. I am happy that Devise/Omniauth does most of the job for me server-side and I'd rather keep it this way, instead of coding that logic in the frontend.
(By the way, is it safe to assume the Linkedin OAuth flow be similar to the Google one mentionned in this answer ?)
I am unsure about whether this can be done the way I see it on the React app (especially the communication of data between the linkedin popup window and the main react view). Also from what I understand the omniauth gem
in rails expects to receive the one-time token from the OAuth provider before it can query the provider twice more (first time to exchange the access token, second time to get user info). Would the following work ?
- Assume my React Client app is hosted on
client.example.com
- Assume my server api is hosted on
api.example.com
- The React app opens a popup windows, that is used to go to the Linkedin auth URI with
- (1) A redirect uri that would point directly to api.example.com
- (2) A redirect_uri on client.example.com, and my React client would then have to forward the token to api.example.com
- The authorization code somewhat reaches my server
api.example.com
, which gets an access code and retrieves user data from Linkedin. It returns to the browser anidentity_id
which can be used for the registration - The
identity_id
is actually returned to the popup window, and transferred back to the main React app (how ?)