Skip to content

Instantly share code, notes, and snippets.

@alex-streza
Created February 10, 2023 22:10
Show Gist options
  • Save alex-streza/16485bbdb4dd33f7ea4b534b296f5f03 to your computer and use it in GitHub Desktop.
Save alex-streza/16485bbdb4dd33f7ea4b534b296f5f03 to your computer and use it in GitHub Desktop.
Figma OAuth Provider implementation for Auth.js (previously next-auth)
import { Provider } from "next-auth/providers";
export const FigmaProvider: Provider = {
id: "figma",
name: "Figma",
type: "oauth",
authorization: {
url: "https://www.figma.com/oauth",
params: {
scope: "file_read",
response_type: "code",
},
},
token: {
url: "https://www.figma.com/api/oauth/token",
async request(context) {
const provider = context.provider;
const res = await fetch(
`https://www.figma.com/api/oauth/token?client_id=${provider.clientId}&client_secret=${provider.clientSecret}&redirect_uri=${provider.callbackUrl}&code=${context.params.code}&grant_type=authorization_code`,
{ method: "POST" }
);
const json = await res.json();
return { tokens: json };
},
},
userinfo: "https://api.figma.com/v1/me",
profile(profile) {
return {
id: profile.id,
name: `${profile.handle}`,
email: profile.email,
image: profile.img_url,
};
},
clientId: process.env.FIGMA_ID,
clientSecret: process.env.FIGMA_SECRET,
};
@Akshithpottigari
Copy link

This isn't working anymore. Can you update this?

@nikitashekhov
Copy link

nikitashekhov commented Dec 14, 2024

Update this accordingly: https://www.figma.com/developers/api#oauth_migration_guide

If you have troubles, just dm me on telegram: https://t.me/NikitaShekhov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment