From a5d60f96ec7e6e053999682dda100e61dcae4241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Fri, 5 Mar 2021 23:31:11 +0100 Subject: [PATCH] feat(provider): add Instagram provider --- src/providers/index.js | 2 ++ src/providers/instagram.js | 50 +++++++++++++++++++++++++++++++++ www/docs/providers/instagram.md | 42 +++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/providers/instagram.js create mode 100644 www/docs/providers/instagram.md diff --git a/src/providers/index.js b/src/providers/index.js index 70b24e012e..20148d6de9 100644 --- a/src/providers/index.js +++ b/src/providers/index.js @@ -18,6 +18,7 @@ import GitHub from './github' import GitLab from './gitlab' import Google from './google' import IdentityServer4 from './identity-server4' +import Instagram from './instagram' import LINE from './line' import LinkedIn from './linkedin' import MailRu from './mailru' @@ -55,6 +56,7 @@ export default { GitLab, Google, IdentityServer4, + Instagram, LINE, LinkedIn, MailRu, diff --git a/src/providers/instagram.js b/src/providers/instagram.js new file mode 100644 index 0000000000..53b793bb6c --- /dev/null +++ b/src/providers/instagram.js @@ -0,0 +1,50 @@ +/** + * @param {import("../server").Provider} options + * @example + * + * ```js + * // pages/api/auth/[...nextauth].js + * import Providers from `next-auth/providers` + * ... + * providers: [ + * Providers.Instagram({ + * clientId: process.env.INSTAGRAM_CLIENT_ID, + * clientSecret: process.env.INSTAGRAM_CLIENT_SECRET + * }) + * ] + * ... + * + * // pages/index + * import { signIn } from "next-auth/client" + * ... + * + * ... + * ``` + * *Resources:* + * - [NextAuth.js Documentation](https://next-auth.js.org/providers/instagram) + * - [Instagram Documentation](https://developers.facebook.com/docs/instagram-basic-display-api/getting-started) + * - [Configuration](https://developers.facebook.com/apps) + */ +export default function Instagram (options) { + return { + id: 'instagram', + name: 'Instagram', + type: 'oauth', + version: '2.0', + scope: 'user_profile', + params: { grant_type: 'authorization_code' }, + accessTokenUrl: 'https://api.instagram.com/oauth/access_token', + authorizationUrl: 'https://api.instagram.com/oauth/authorize?response_type=code', + profileUrl: 'https://graph.instagram.com/me?fields=id,username,account_type,name', + async profile (profile) { + return { + id: profile.id, + name: profile.username, + email: null, + image: null + } + } + } +} diff --git a/www/docs/providers/instagram.md b/www/docs/providers/instagram.md new file mode 100644 index 0000000000..f41f718585 --- /dev/null +++ b/www/docs/providers/instagram.md @@ -0,0 +1,42 @@ +--- +id: instagram +title: Instagram +--- + +## Documentation + +https://developers.facebook.com/docs/instagram-basic-display-api/getting-started + +## Configuration + +https://developers.facebook.com/apps/ + +## Example + +```jsx +// pages/api/auth/[...nextauth].js +import Providers from `next-auth/providers` +... +providers: [ + Providers.Instagram({ + clientId: process.env.INSTAGRAM_CLIENT_ID, + clientSecret: process.env.INSTAGRAM_CLIENT_SECRET + }) +] +... +// pages/index.jsx +import { signIn } from "next-auth/client" +... + +... +``` + +:::warning +Email address is not returned by the Instagram API. +::: + +:::tip +Instagram display app required callback URL to be configured in your Facebook app and Facebook required you to use **https** even for localhost! In order to do that, you either need to [add an SSL to your localhost](https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/) or use a proxy such as [ngrock](https://ngrok.com/docs). +::: \ No newline at end of file