Skip to content

Instantly share code, notes, and snippets.

@alex-streza
Created February 10, 2023 22:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment