Skip to content

Commit fbb5a12

Browse files
afoyerbalazsorban44
authored andcommitted
feat(provider): finish Reddit provider and add documentation (#1094)
* Create reddit.md * uncommented profile callback * Update reddit.md * fix lint issues * added reddit provider * added reddit provider * Add Reddit Provider For some reason a bunch of providers got deleted in the last commit * Add Reddit Provider * Add Reddit Provider
1 parent 70a186c commit fbb5a12

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed

src/providers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import MailRu from './mailru'
2323
import Mixer from './mixer'
2424
import Netlify from './netlify'
2525
import Okta from './okta'
26+
import Reddit from './reddit'
2627
import Slack from './slack'
2728
import Spotify from './spotify'
2829
import Strava from './strava'
@@ -57,6 +58,7 @@ export default {
5758
Mixer,
5859
Netlify,
5960
Okta,
61+
Reddit,
6062
Slack,
6163
Spotify,
6264
Strava,

src/providers/reddit.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Logging in works but trying to retrieve the profile results in 401 unauthorized
21
export default (options) => {
32
return {
43
id: 'reddit',
@@ -12,12 +11,12 @@ export default (options) => {
1211
'https://www.reddit.com/api/v1/authorize?response_type=code',
1312
profileUrl: 'https://oauth.reddit.com/api/v1/me',
1413
profile: (profile) => {
15-
// return {
16-
// id: profile.id,
17-
// name: profile.name,
18-
// image: null,
19-
// email: null,
20-
// };
14+
return {
15+
id: profile.id,
16+
name: profile.name,
17+
image: null,
18+
email: null
19+
}
2120
},
2221
...options
2322
}

www/docs/configuration/providers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ NextAuth.js is designed to work with any OAuth service, it supports OAuth 1.0, 1
3434
* [Mixer](/providers/mixer)
3535
* [Netlify](/providers/netlify)
3636
* [Okta](/providers/okta)
37+
* [Reddit](/providers/reddit)
3738
* [Slack](/providers/slack)
3839
* [Spotify](/providers/spotify)
3940
* [Strava](/providers/strava)

www/docs/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can use also NextAuth.js with any database using a custom database adapter,
2323

2424
### What authentication services does NextAuth.js support?
2525

26-
NextAuth.js includes built-in support for signing in with Amazon Cognito, Apple, Atlassian, Auth0, Azure Active Directory B2C, Basecamp, Battle.net, Box, Bungie, Discord, Facebook, Foursquare, FusionAuth, GitHub, GitLab, Google, IdentityServer4, LINE, LinkedIn, Mail.ru, Mixer, Netlify, Okta, Slack, Spotify, Strava, Twitch, Twitter, VK and Yandex. (See also: [Providers](/configuration/providers))
26+
NextAuth.js includes built-in support for signing in with Amazon Cognito, Apple, Atlassian, Auth0, Azure Active Directory B2C, Basecamp, Battle.net, Box, Bungie, Discord, Facebook, Foursquare, FusionAuth, GitHub, GitLab, Google, IdentityServer4, LINE, LinkedIn, Mail.ru, Mixer, Netlify, Okta, Reddit, Slack, Spotify, Strava, Twitch, Twitter, VK and Yandex. (See also: [Providers](/configuration/providers))
2727

2828
NextAuth.js also supports email for passwordless sign in, which is useful for account recovery or for people who are not able to use an account with the configured OAuth services (e.g. due to service outage, account suspension or otherwise becoming locked out of an account).
2929

www/docs/providers/reddit.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
id: reddit
3+
title: Reddit
4+
---
5+
6+
## Documentation
7+
8+
https://www.reddit.com/dev/api/
9+
10+
## Configuration
11+
12+
https://www.reddit.com/prefs/apps/
13+
14+
## Example
15+
16+
```js
17+
import Providers from `next-auth/providers`
18+
...
19+
providers: [
20+
Providers.Reddit({
21+
clientId: process.env.REDDIT_CLIENT_ID,
22+
clientSecret: process.env.REDDIT_CLIENT_SECRET
23+
})
24+
}
25+
...
26+
```
27+
28+
:::warning
29+
Reddit requires authorization every time you go through their page.
30+
:::
31+
32+
:::warning
33+
Only allows one callback URL per Client ID / Client Secret.
34+
:::
35+
36+
:::tip
37+
This Provider template only has a one hour access token to it and only has the 'identity' scope. If you want to get a refresh token as well you must follow this:
38+
39+
```js
40+
providers: [
41+
{
42+
id: "reddit",
43+
name: "Reddit",
44+
clientId: process.env.REDDIT_CLIENT_ID,
45+
clientSecret: process.env.REDDIT_CLIENT_SECRET,
46+
scope: "identity mysubreddits read", //Check Reddit API Documentation for more. The identity scope is required.
47+
type: "oauth",
48+
version: "2.0",
49+
params: { grant_type: "authorization_code" },
50+
accessTokenUrl: " https://www.reddit.com/api/v1/access_token",
51+
authorizationUrl:
52+
"https://www.reddit.com/api/v1/authorize?response_type=code&duration=permanent",
53+
profileUrl: "https://oauth.reddit.com/api/v1/me",
54+
profile: (profile) => {
55+
return {
56+
id: profile.id,
57+
name: profile.name,
58+
email: null,
59+
}
60+
}
61+
}
62+
]
63+
```
64+
:::

www/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module.exports = {
4949
'providers/mixer',
5050
'providers/netlify',
5151
'providers/okta',
52+
'providers/reddit',
5253
'providers/slack',
5354
'providers/spotify',
5455
'providers/strava',

0 commit comments

Comments
 (0)