Skip to content

Commit d32ec28

Browse files
committed
feat(provider): add Instagram provider (nextauthjs#1447)
Co-authored-by: @PolMrt [email protected]
1 parent 032e01a commit d32ec28

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

src/providers/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import GitHub from './github'
1818
import GitLab from './gitlab'
1919
import Google from './google'
2020
import IdentityServer4 from './identity-server4'
21+
import Instagram from './instagram'
2122
import LINE from './line'
2223
import LinkedIn from './linkedin'
2324
import MailRu from './mailru'
@@ -55,6 +56,7 @@ export default {
5556
GitLab,
5657
Google,
5758
IdentityServer4,
59+
Instagram,
5860
LINE,
5961
LinkedIn,
6062
MailRu,

src/providers/instagram.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @param {import("../server").Provider} options
3+
* @example
4+
*
5+
* ```js
6+
* // pages/api/auth/[...nextauth].js
7+
* import Providers from `next-auth/providers`
8+
* ...
9+
* providers: [
10+
* Providers.Instagram({
11+
* clientId: process.env.INSTAGRAM_CLIENT_ID,
12+
* clientSecret: process.env.INSTAGRAM_CLIENT_SECRET
13+
* })
14+
* ]
15+
* ...
16+
*
17+
* // pages/index
18+
* import { signIn } from "next-auth/client"
19+
* ...
20+
* <button onClick={() => signIn("instagram")}>
21+
* Sign in
22+
* </button>
23+
* ...
24+
* ```
25+
* *Resources:*
26+
* - [NextAuth.js Documentation](https://next-auth.js.org/providers/instagram)
27+
* - [Instagram Documentation](https://developers.facebook.com/docs/instagram-basic-display-api/getting-started)
28+
* - [Configuration](https://developers.facebook.com/apps)
29+
*/
30+
export default function Instagram (options) {
31+
return {
32+
id: 'instagram',
33+
name: 'Instagram',
34+
type: 'oauth',
35+
version: '2.0',
36+
scope: 'user_profile',
37+
params: { grant_type: 'authorization_code' },
38+
accessTokenUrl: 'https://api.instagram.com/oauth/access_token',
39+
authorizationUrl: 'https://api.instagram.com/oauth/authorize?response_type=code',
40+
profileUrl: 'https://graph.instagram.com/me?fields=id,username,account_type,name',
41+
async profile (profile) {
42+
return {
43+
id: profile.id,
44+
name: profile.username,
45+
email: null,
46+
image: null
47+
}
48+
}
49+
}
50+
}

www/docs/providers/instagram.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
id: instagram
3+
title: Instagram
4+
---
5+
6+
## Documentation
7+
8+
https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
9+
10+
## Configuration
11+
12+
https://developers.facebook.com/apps/
13+
14+
## Example
15+
16+
```jsx
17+
// pages/api/auth/[...nextauth].js
18+
import Providers from `next-auth/providers`
19+
...
20+
providers: [
21+
Providers.Instagram({
22+
clientId: process.env.INSTAGRAM_CLIENT_ID,
23+
clientSecret: process.env.INSTAGRAM_CLIENT_SECRET
24+
})
25+
]
26+
...
27+
// pages/index.jsx
28+
import { signIn } from "next-auth/client"
29+
...
30+
<button onClick={() => signIn("instagram")}>
31+
Sign in
32+
</button>
33+
...
34+
```
35+
36+
:::warning
37+
Email address is not returned by the Instagram API.
38+
:::
39+
40+
:::tip
41+
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).
42+
:::

0 commit comments

Comments
 (0)