🌐
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
🌐
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....
🌐
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.
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
🌐
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!

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).

🌐
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 ...
🌐
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
gist.github.com › kemitche › 9749639
reddit OAuth 2.0 Python Webserver Example · GitHub
def get_token(code): client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET) post_data = {"grant_type": "authorization_code", "code": code, "redirect_uri": REDIRECT_URI} headers = base_headers() # Use the corrected URL below response = requests.post("https://www.reddit.com/api/v1/access_token", auth=client_auth, headers=headers, data=post_data) token_json = response.json() # Check if 'access_token' is in the response before trying to access it if "access_token" in token_json: return token_json["access_token"] else: # Handle the error gracefully if the token isn't in the response print("Error fetching token.") return None
🌐
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 › 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
🌐
Reddit
reddit.com › r/redditdev › using the reddit api after 2 years - oauth and praw has me confused after the api changes
r/redditdev on Reddit: Using the Reddit API after 2 years - OAuth and PRAW has me confused after the API changes
August 29, 2023 -

To my understanding, the changes mean that users with OAuth have 100 requests per minute - which satisfies my requirements. I've been looking around for some proper documentation about all this.

I found the following https://github.com/reddit-archive/reddit/wiki/OAuth2-Quick-Start-Example#first-steps that provides the curl command to get an access token and works fine. Is that all the documentation there is?

Is there anyway I can do the same via Praw (or should I just use the token from the above with Praw)? Additionally, the above resource doesn't show me how to access refresh tokens, is there a separate curl command for them?

I apologize if this is a stupid question but I can't seem to find any coherent docs and haven't used the API for a long time.