Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OAuth2 flow for "web app" #45

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

bevzzz
Copy link

@bevzzz bevzzz commented Apr 6, 2023

Related issue: #44

Description

This MR introduces several changes to support "web app" clients:

  • AuthCodeURL is a thin wrapper around oauth2.Config.AuthCodeURL for building URLs for requesting authorization from users.
  • Create a client and authorize it by exchanging code immediately after receiving it by providing WithWebAppCode option to the constructor.
    OR
  • Refresh an existing access token with a refresh_token by creating a client with a WithWebAppRefresh option. This is handy in case you want to persist the refresh_token elsewhere and avoid requesting authorization from your uses repeatedly.

Please note, that in order to complete the authorization with a web app, you will also need to host a service receiving code-redirects from Reddit (see docs on redirect_uri), but at the moment it seems beyond the scope of this PR or this package, for that matter.
See unit tests for examples of how to use these options.

The changes to the packages API are minimal and are fully backwards-compatible:

  • New OAuth options are few and have self-descriptive names.
  • Script is the default AppType for a reddit client.
  • What little refactoring I did does not change the API (purely code style)

Note: @vartanbeno I figured this repo is no longer being maintained and I changed the export path to github.com/bevzzz/go-reddit/v2 in the go.mod because I wanted to use the updated version of the package in my other project. If you decide to merge this PR, please let me know and I will revert that change.

bevzzz and others added 10 commits January 14, 2023 15:15
…rAgent

Following the pattern of context.With[Something] functions, which, too,
clone the object and modify it
New Opts allow creating a reddit client with a "code"
or with a "refresh_token".

Added OAuth2 flow instructions to package docs.
A think wrapper around oauth.Config.AuthCodeURL
with the notion of {"duration": "permanent"} parameter for Reddit API

Currently only works with defaultAuthURL
webAppOathParams > webAppOAuthParams

vartanbeno#44
This is the lingo reddit documentation uses

vartanbeno#44
- hidden
- removed_by_category
- banned_by
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant