Figma Plugin ↔ GitHub REST API: Unresolved OAuth Scope Negotiation Across Figma Updates
0 reputation · 19 Jan 2023, 13:23 UTC
0 reputation · 19 Jan 2023, 13:23 UTC
Ensure that a Figma plugin can maintain valid OAuth scopes when Figma releases update the Plugin API, without breaking existing design files.
Figma’s Plugin API currently stores the GitHub access token in local storage and refreshes it automatically, but the documentation does not specify how to detect a scope mismatch after an API update. Plugin authors must decide whether to re‑authenticate automatically, prompt the user, or rely on a fallback scope. Additionally, backward‑compatibility demands that older plugin releases continue to function until the user explicitly updates the plugin.
What strategy should plugins adopt to negotiate and persist OAuth scopes across Figma updates while preserving backward compatibility?
35275 reputation · 20 Jan 2023, 00:02 UTC
To maintain stability across Figma updates and preserve backward compatibility, plugins should adopt an Incremental Authorization strategy paired with Header-based Scope Verification. Rather than requesting a comprehensive set of permissions upfront, the plugin should request the minimum viable scopes for core functionality and prompt for additional permissions only when a user triggers a feature that requires them.
Since Figma does not provide a native runtime hook to detect external OAuth scope changes, the plugin must manually verify the token's capabilities during the initialization phase or before high-privilege API calls.
GET /user endpoint. GitHub returns the currently authorized scopes in the X-OAuth-Scopes response header.To ensure older plugin releases remain functional after a Figma update or a change in your backend scope requirements:
figma.clientStorage, but accompany it with a metadata key (e.g., auth_version) that tracks which version of your scope requirements the token was issued under.You can verify the current scopes of a stored token using a simple curl request to check the headers:
curl -H "Authorization: token YOUR_ACCESS_TOKEN" https://api.github.com/user
Inspect the X-OAuth-Scopes header in the response to confirm which permissions are active.
This approach assumes the use of standard GitHub OAuth apps. If you migrate to GitHub Fine-Grained Personal Access Tokens, the scope negotiation logic changes significantly as permissions are resource-specific rather than global. We assume the plugin uses a backend proxy or a secure handshake to exchange codes for tokens, as Figma plugins cannot securely store client secrets.
Diagnostic Detail Needed: Are you utilizing a middleware server to handle the OAuth exchange, or are you relying on a third-party authentication provider?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.