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

Added [WebAuthenticator], which allows for user authentication through a browser #5

Merged
merged 5 commits into from
Jul 13, 2017

Conversation

bkonyi
Copy link
Member

@bkonyi bkonyi commented Jul 7, 2017

Added [WebAuthenticator], which allows for user authentication at https://www.reddit.com/api/v1/authorize. Authentication + authorization have been tested, but nothing else at the moment.

https://www.reddit.com/api/v1/authorize. Authentication + authorization
have been tested, but nothing else at the moment.
@bkonyi
Copy link
Member Author

bkonyi commented Jul 7, 2017

@leonsenft

Map<String, String> revokeAccess = new Map<String, String>();
revokeAccess[kTokenKey] = accessToken;
revokeAccess[kTokenTypeHintKey] = 'access_token';
List<Map> tokens = new List<Map>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid LHS type, and use literals when possible. For example

final tokens = <Map>[];

// Retrieve the client ID and secret.
String clientId = _grant.identifier;
String clientSecret = _grant.secret;
for (int i = 0; i < tokens.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer for-in loops when the index isn't used for anything other than indexing the collection.

for (var token in tokens) {
  ...
}

/// https://github.com/reddit/reddit/wiki/OAuth2-App-Types for descriptions of
/// valid app types.
class WebAuthenticator extends Authenticator {
static WebAuthenticator Create(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String userInfo = '$clientId:$clientSecret';
// TODO(bkonyi) we shouldn't have hardcoded urls like this. Move to common
// file with all API related strings.
Uri path = Uri.parse(r'https://www.reddit.com/api/v1/revoke_token');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid LHS type unless it's unclear from context or type inference doesn't infer the desired type.

Future _requestToken(Map<String, String> accountInfo) async {
// Retrieve the client ID and secret.
String clientId = _grant.identifier;
String clientSecret = _grant.secret;
String userInfo = null;

if ((clientId != null) && (clientSecret != null)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Unnecessary parentheses. While generally useful if precedence rules are unclear, I'd argue this condition is simple enough the parentheses don't improve clarity.

_client = await _client.refreshCredentials();
}

Uri _redirect;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Fields are generally declared at the top of your class before constructors.

Copy link

@leonsenft leonsenft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, most of my comments are just nit-picky style guidelines which are largely subjective.

I'd recommend using final on local variable declarations. It's a good defensive coding tool that helps prevent bugs and helps readers reason about your code. There's a lint available, but it does have some false positives: http://dart-lang.github.io/linter/lints/prefer_final_locals.html

String clientSecret = _grant.secret;
final clientId = _grant.identifier;
final clientSecret = _grant.secret;
String userInfo = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All declarations are implicitly null. There's a lint for this: http://dart-lang.github.io/linter/lints/avoid_init_to_null.html 😉

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.

None yet

2 participants