Skip to content

Commit

Permalink
Added Reddit.createInstalledFlowInstance to allow for authentication of
Browse files Browse the repository at this point in the history
installed applications.

Fixes #43
  • Loading branch information
bkonyi committed May 31, 2019
1 parent 6a952ea commit 4393392
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Change Log
=================================
## Version 0.5.2 (Unreleased)
* Added optional `waitForResponse` to `clearVote`, `downvote`, and `upvote`, which
allows for these calls to complete without waiting for a response from Reddit.
* Added `Reddit.createInstalledFlowInstance` to help with authenticating installed
applications with no client secret.

## Version 0.5.1+1 (2019/05/17)
* Fixed analysis issues.

Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/wikipage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ class WikiPageModeration {
.replaceAll(_kMethodRegExp, method);
try {
await wikiPage.reddit.post(url, data, objectify: false);
} on DRAWNotFoundException catch (e) {
// ignore: unused_catch_clause
} on DRAWNotFoundException catch (e) {
throw DRAWInvalidRedditorException(redditor);
}
}
Expand Down
36 changes: 36 additions & 0 deletions lib/src/reddit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ class Reddit {
'Unable to get valid OAuth token for read-only instance');
}

/// Creates a new [Reddit] instance for use with the installed application
/// authentication flow. This instance is not authenticated until a valid
/// response code is provided to `WebAuthenticator.authorize`
/// (see test/auth/web_auth.dart for an example usage).
///
/// [clientId] is the identifier associated with your authorized application
/// on Reddit. To get a client ID, create an authorized application
/// [here](http://www.reddit.com/prefs/apps).
///
/// [userAgent] is an arbitrary identifier used by the Reddit API to
/// differentiate between client instances. This should be relatively unique.
///
/// [redirectUri] is the redirect URI associated with your Reddit application.
///
/// [tokenEndpoint] is a [Uri] to an alternative token endpoint. If not
/// provided, [defaultTokenEndpoint] is used.
///
/// [authEndpoint] is a [Uri] to an alternative authentication endpoint. If not
/// provided, [defaultAuthTokenEndpoint] is used.
///
/// [configUri] is a [Uri] pointing to a 'draw.ini' file, which can be used to
/// populate the previously described parameters.
///
/// [siteName] is the name of the configuration to use from draw.ini. Defaults
/// to 'default'.
static Reddit createInstalledFlowInstance(
{String clientId,
String userAgent,
Uri redirectUri,
Uri tokenEndpoint,
Uri authEndpoint,
Uri configUri,
String siteName = 'default'}) =>
Reddit._webFlowInstance(clientId, '', userAgent, redirectUri,
tokenEndpoint, authEndpoint, configUri, siteName);

/// Creates a new read-only [Reddit] instance for web and script applications.
///
/// [clientId] is the identifier associated with your authorized application
Expand Down
2 changes: 1 addition & 1 deletion test/auth/web_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Future<void> main() async {
redirectUri: Uri.parse(redirect),
userAgent: userAgent + '_authenticated');
expect(reddit.auth.userAgent, userAgent + '_authenticated');
// Create our implicit grant flow URI.
// Create our code grant flow URI.
final dest = reddit.auth.url([scope], expectedState);

// ------------------------------------------------------------------ //
Expand Down

0 comments on commit 4393392

Please sign in to comment.