🌐
GitHub
github.com › reddit-archive › reddit › wiki › OAuth2
OAuth2 · reddit-archive/reddit Wiki · GitHub
In order to make requests to reddit's API via OAuth, you must acquire an Authorization token, either on behalf of a user or for your client (see Application Only OAuth, below).
Author   reddit-archive
🌐
GitHub
github.com › aiham › reddit-oauth
GitHub - aiham/reddit-oauth: Reddit API wrapper
var RedditApi = require('reddit-oauth'); var reddit = new RedditApi({ app_id: 'your_app_id', app_secret: 'your_app_secret', redirect_uri: 'your_app_redirect_uri' }); // Authenticate with username/password reddit.passAuth( 'your_reddit_username', 'your_reddit_password', function (success) { if (success) { // Print the access token we just retrieved console.log(reddit.access_token); } } ); // Get the OAuth URL to redirect users to // Scopes are defined here: https://github.com/reddit/reddit/wiki/OAuth2 reddit.oAuthUrl('some_state', 'identity'); // After the user is redirected back to us, grab the query string // object and exchange it for a set of access and refresh tokens.
Starred by 7 users
Forked by 5 users
Languages   JavaScript
🌐
GitHub
github.com › reddit-archive › reddit › wiki › oauth2-quick-start-example
OAuth2 Quick Start Example · reddit-archive/reddit Wiki · GitHub
In [1]: import requests In [2]: import requests.auth In [3]: client_auth = requests.auth.HTTPBasicAuth('p-jcoLKBynTLew', 'gko_LXELoV07ZBNUXrvWZfzE3aI') In [4]: post_data = {"grant_type": "password", "username": "reddit_bot", "password": "snoo"} In [5]: headers = {"User-Agent": "ChangeMeClient/0.1 by YourUsername"} In [6]: response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, data=post_data, headers=headers) In [7]: response.json() Out[7]: {u'access_token': u'fhTdafZI-0ClEzzYORfBSCR7x3M', u'expires_in': 3600, u'scope': u'*', u'token_type': u'bearer'} Use the token. Notice that for using the token, requests are made to https://oauth.reddit.com.
Author   reddit-archive
🌐
GitHub
github.com › jimmycodesocial › simple-oauth2-reddit
GitHub - jimmycodesocial/simple-oauth2-reddit: A simple Node.js client library for Reddit OAuth2.
https://github.com/reddit-archive/reddit/wiki/OAuth2#authorization · returnError · false · When is false (default), will call the next middleware with the error object. When is true, will set req.tokenError to the error, and call the next middleware as if there were no error. authorizeHost · 'https://www.reddit.com' authorizePath · '/api/v1/authorize' tokenHost ·
Author   jimmycodesocial
🌐
GitHub
github.com › not-an-aardvark › reddit-oauth-helper
GitHub - not-an-aardvark/reddit-oauth-helper: A quick script that creates reddit oauth tokens for you
A quick script that creates reddit oauth tokens for you - not-an-aardvark/reddit-oauth-helper
Starred by 156 users
Forked by 17 users
Languages   JavaScript 88.8% | CSS 7.5% | HTML 3.7%
🌐
GitHub
github.com › PaulC91 › redditapi
GitHub - PaulC91/redditapi: Tools to interact with the reddit oauth API in R
library(redditapi) library(dplyr) client_id <- Sys.getenv("REDDIT_CLIENT_ID") # the client id of your api application secret <- Sys.getenv("REDDIT_SECRET") # the secret of your api application agent <- Sys.getenv("REDDIT_AGENT") # the name of your api application username <- Sys.getenv("REDDIT_USERNAME") # your personal reddit username password <- Sys.getenv("REDDIT_PASSWORD") # your personal reddit password · token <- get_reddit_token( agent = agent, client_id = client_id, secret = secret, username = username, password = password ) Because we have authenticated and are using the OAuth2 api, you can access private subreddits you are a member of.
Author   PaulC91
🌐
GitHub
gist.github.com › aaronhoffman › b59585d507601b05d8db02493eaaf73e
Reddit OAuth API C# .NET · GitHub
Reddit OAuth API C# .NET. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › sirkris › Reddit.NET
GitHub - sirkris/Reddit.NET: A Reddit API library for .NET Standard with OAuth support. Written in C#.
A Reddit API library for .NET Standard with OAuth support. Written in C#. - sirkris/Reddit.NET
Starred by 507 users
Forked by 75 users
Languages   C# 99.9% | HTML 0.1%
Find elsewhere
🌐
GitHub
github.com › r-lib › httr › blob › main › demo › oauth2-reddit.R
httr/demo/oauth2-reddit.R at main · r-lib/httr
reddit <- oauth_endpoint( authorize = "https://www.reddit.com/api/v1/authorize", access = "https://www.reddit.com/api/v1/access_token" ) · # 2. Register an application at https://www.reddit.com/prefs/apps · # Make sure to register http://localhost:1410/ as the "redirect uri".
Author   r-lib
Top answer
1 of 2
24

As of right now, you cannot retrieve a permanent access token. You have 2 options that come close.

The first is to request a "refresh" token when using the standard OAuth flow. That's what you're doing by sending "duration" as "permanent" in your code. The refresh token can be used to automatically retrieve new 1 hour access tokens without user intervention; the only manual steps are on the initial retrieval of the refresh token.

The second alternative, which applies only when writing a script for personal use, is to use the password grant type. The steps are described in more detail on reddit's "OAuth Quick Start" wiki page, but I'll summarize here:

  1. Create an OAuth client (under https://www.reddit.com/prefs/apps) with type = "script"
  2. Make a request to https://www.reddit.com/api/v1/access_token with POST parameters grant_type=password&username=<USERNAME>&password=<PASSWORD>. Send your client ID and secret as HTTP basic authentication. <USERNAME> must be registered as a developer of the OAuth 2 client ID you send.
2 of 2
17

A client_id and client_secret can be generated for a reddit account by going to https://www.reddit.com/prefs/apps and creating an app:


The part I have hidden is my client_id.

Then you can use a client like praw to access reddit e.g. with Python:

import praw
r = praw.Reddit(client_id='insert id here',
                client_secret='insert secret here',
                user_agent='insert user agent')
page = r.subreddit('aww')
top_posts = page.hot(limit=None)
for post in top_posts:
    print(post.title, post.ups)

You could use your current browser's user agent, which can be easily found by google searching "what is my user agent" (among other ways).

🌐
Readthedocs
redditclient.readthedocs.io › en › latest › oauth
Oauth Setup - Reddit::Client Documentation
While Reddit::Client supports ... documented in Main Methods. Documentation for the entire "web"-type flow can be found at https://github.com/reddit-archive/reddit/wiki/OAuth2....
🌐
DEV Community
dev.to › imtyrelchambers › build-a-reddit-scraper-authenticating-with-reddit-oauth-4519
Build a Reddit Scraper: Authenticating With Reddit OAuth - DEV Community
July 15, 2019 - To get started with authenticating with the Reddit API, we need to create a developer app that will allow us to actually use the more advanced features of Reddit’s API. For reference, you can find everything I’m talking about, here: https://github.com/reddit-archive/reddit/wiki/oauth2
🌐
GitHub
github.com › sonsongithub › reddift
GitHub - sonsongithub/reddift: Swift Reddit API Wrapper
reddift is Swift Reddit API Wrapper framework, and includes a browser is developed using the framework. Supports OAuth2(is not supported on tvOS currently).
Starred by 238 users
Forked by 52 users
Languages   Swift 91.2% | HTML 7.4%
🌐
GitHub
github.com › rtheunissen › oauth2-reddit
GitHub - rtheunissen/oauth2-reddit: Reddit OAuth2 provider for league/oauth2-client
Reddit OAuth2 provider for league/oauth2-client. Contribute to rtheunissen/oauth2-reddit development by creating an account on GitHub.
Starred by 12 users
Forked by 11 users
Languages   PHP
🌐
Reddit
reddit.com › r › oauth
OAuth 1.0a, OAuth 2, OpenID Connect
February 11, 2015 - The app uses OAuth for its authorization requests. So I've created an instance of Filip Skokan's `node-oidc-provider` (https://github.com/panva/node-oidc-provider) to handle API access. Currently, when the app requests authorization ...
🌐
Reddit
reddit.com › r/github › clarification needed: can oauth token be used for github api access?
r/github on Reddit: Clarification Needed: Can OAuth Token Be Used for GitHub API Access?
January 29, 2024 -

Hello everyone,

I'm currently in the process of setting up access to GitHub repositories via the GitHub API for a project. My intention is to allow users to log in with their GitHub accounts and then view all the repositories associated with their account, along with their pull requests.

I've been exploring OAuth tokens as a potential solution for authentication, but I'm uncertain if this approach is suitable for accessing user repositories. Can anyone confirm if OAuth tokens can indeed be utilized in this manner?

Additionally, if you have any insights or examples of the user flow for logging in with GitHub and accessing repository data via the API, I'd greatly appreciate it!

Thank you for your assistance!

🌐
Reddit
reddit.com › r/redditdev › reddit api oauth2 for web app development
r/redditdev on Reddit: Reddit API Oauth2 for Web App Development
February 5, 2021 -

Hello All,

I'm trying to learn how to use the Reddit API for non-anonymous API requests. I'm having trouble how to set up a dev environment that lets me actually request data (user, history, read api endpoints). I created a nodejs server that can successfully request authentication for the user and retrieve the appropriate access token, but I don't know how to use this server, or any other method, to use this token on the same dev machine due to CORS errors.

How do I go about developing with the Reddit API for a web app created in React? I'm using this opportunity to try to learn the Reddit API and React. Do I need to host a server elsewhere to be able to develop the actual user-facing web application?

Thanks in advance!

Top answer
1 of 2
4
The are a couple strategies you can use for this. The way I normally do it is to have a server (e.g. your node server) that handles the auth flow and is also responsible for making all the API requests to Reddit. Each user that authenticates has their access tokens stored in a session. Then, for example if your web app needs to get info for the currently authenticated user, it would send a request to your server, which would in turn send a request to the Reddit API, authenticating with that user's access token. One benefit of this approach is that the client (your React app) never sees the access/refresh tokens. It also allows you to filter or modify the data Reddit returns before passing it to your web app, allowing you to create a layer of abstraction between the Reddit API and your frontend if you want. The other method is to have your React app use the "Implicit Grant" flow to retrieve tokens without a server. This is a modified OAuth flow used for applications where requests need to be made from an environment that can't be trusted with your application's client secret. If you had a Node server working for Reddit auth, one step of the authentication process you already have includes sending your client secret, but you can't include that value in a React app because that would expose it. The implicit grant flow is documented here . The obvious upside to this method is that you don't have to write a server - this enables you to write a truly thick client without relying on a separate service (other than Reddit) for data processing. Note that you'll have to use a different type of API app to use the implicit grant flow - this is mentioned in the docs.
2 of 2
2
Thanks for the silver kind stranger!
🌐
GitHub
github.com › reddit › node-api-client
GitHub - reddit/node-api-client
An api instance is created in the global scope (api), from which you can call any of the API methods. Use help in the repl to learn more. If you want to use your account to see thigns like your subscriptions, saved, etc: ./repl will use the environment variable 'TOKEN' if supplied. export TOKEN='my-super-secret-secure-oauth-token' ./repl
Starred by 92 users
Forked by 29 users
Languages   JavaScript