-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): add Instagram provider (#1447)
Co-authored-by: @PolMrt pol@hey.com
- Loading branch information
1 parent
0e20b60
commit ed5cc4a
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
* ... | ||
* <button onClick={() => signIn("instagram")}> | ||
* Sign in | ||
* </button> | ||
* ... | ||
* ``` | ||
* *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 | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
... | ||
<button onClick={() => signIn("instagram")}> | ||
Sign in | ||
</button> | ||
... | ||
``` | ||
|
||
:::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). | ||
::: |
ed5cc4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: