Created
February 10, 2023 22:10
-
-
Save alex-streza/16485bbdb4dd33f7ea4b534b296f5f03 to your computer and use it in GitHub Desktop.
Figma OAuth Provider implementation for Auth.js (previously next-auth)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}; |
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
This isn't working anymore. Can you update this?