Skip to content

Instantly share code, notes, and snippets.

@nikitashekhov
Created December 28, 2024 12:17
Show Gist options
  • Save nikitashekhov/128fc8538b10774f30d487fff89323c4 to your computer and use it in GitHub Desktop.
Save nikitashekhov/128fc8538b10774f30d487fff89323c4 to your computer and use it in GitHub Desktop.
Figma Provider for NextAuth NextJS. Tested on latest versions
import { Provider } from "next-auth/providers";
const clientId = process.env.FIGMA_CLIENT_ID
const clientSecret = process.env.FIGMA_CLIENT_SECRET
const base64Encoded = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
const authHeader = `Basic ${base64Encoded}`;
export const FigmaProvider: Provider = {
id: "figma",
name: "Figma",
type: "oauth",
authorization: {
url: "https://www.figma.com/oauth",
params: {
scope: "files:read",
response_type: "code",
state: "YOUR_STATE_TO_UPDATE_TOKENS"
},
},
token: {
url: "https://api.figma.com/v1/oauth/token",
async request(context: any) {
const provider = context.provider;
const res = await fetch(
`https://api.figma.com/v1/oauth/token?redirect_uri=${provider.callbackUrl}&code=${context.params.code}&grant_type=authorization_code`,
{
method: "POST",
headers: {
'Authorization': authHeader,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
);
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_CLIENT_ID,
clientSecret: process.env.FIGMA_CLIENT_SECRET
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment