How to pass token to plugin from browser

Hello,
I am developing a plugin and wants to authenticate user by redirecting from browser to plugin similar to the figma desktop app login flow. Its done with custom URI scheme and is possible with sketch. Is the same possible with figma.

I don’t know exactly how it works but I heard that you can implement Oauth flow by using websockets. Haven’t seen any docs on how to do it though.

Here’s one approach you can take, assuming you are using an OAuth flow (like e.g. authenticate with Figma, Google, etc.):

  1. Generate a random code from the Figma plugin
  2. Open the OAuth URL from the plugin with the code as a query parameter in the callback/redirect uri
  3. Handle the OAuth callback on your server at the redirect uri and store the result in a cache of some sort
  4. From the plugin, poll the server for the OAuth callback result using the code you generated in step 1. Match the code against what you have on the server (e.g. you could use the code as a key in the cache) to get the result.

Essentially I am following something like this: Device Authorization Flow (although I’m not using Auth0 since I only need Figma login in my case).

I’m doing this with Figma OAuth - your use case might be slightly different but I think you will essentially need to use the polling approach since you don’t have access to a server within the Figma environment.