Coder Social home page Coder Social logo

Comments (15)

StefanLobbenmeier avatar StefanLobbenmeier commented on September 21, 2024 1

Sorry for commenting on this long closed issue, but I wanted to let you know that I struggled with the same question and could not find any documentation on the error. When chosing the type "installed app", you dont have a secret, yet there is no constructor in DRAW that doesnt contain a secret except for the UntrustedReadOnlyIntstance. I ended up solving this issue like this:

`

// Create a Reddit instance using a configuration file in the
// current directory.
_reddit = await Reddit.createWebFlowInstance(
  clientId: client_id,
  clientSecret: "", //not null, but empty string
  userAgent: userAgent,
  redirectUri: Uri.parse(redirect_url),
);

`

but I would much rather prefer having a dedicated constructor that does the same. What do you think?

(By the way, using draw: ^0.4.6+1)

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Hi @Ivaskuu,

Thanks for the issue! It looks like there's some potential issues with providing the arguments to Reddit.createInstance but we can get around this for now using a draw.ini configuration file. Here's some example code:

import 'package:draw/draw.dart';

main() async {
  // Create a `Reddit` instance using a configuration file.
  final reddit = await Reddit.createInstance(userAgent: 'foobar', configUri: Uri.parse('draw.ini'));

  // Build the URL used for authentication. See documentation for `WebAuthenticator` for parameters.
  final auth_url = reddit.auth.url(['*'], 'foobar'));
  
  // ...
  // Complete authentication at `auth_url` in the browser and retrieve the `code` query
  // parameter from the redirect URL.
  // ...

  // Assuming the `code` query parameter is stored in a variable `auth_code`, we pass it to the
  // `authorize` method in the `WebAuthenticator`.
  await reddit.auth.authorize(auth_code);

  // If everything worked correctly, we should be able to retrieve information about the authenticated
  // account.
  print(await reddit.user.me());
}

And here's an example draw.ini suitable for web based authentication:

default=default
reddit_url='https://www.reddit.com'
oauth_url=https://oauth.reddit.com
redirect_uri=https://www.google.com
client_id=YOUR_CLIENT_ID_HERE
client_secret=YOUR_SECRET_HERE
userAgent=draw_testing_agent

I've registered my Reddit application's redirect URI to be https://www.google.com, but you'll need to replace that with whatever redirect you have registered.

The format of draw.ini configuration files is very similar to that of praw.ini files used by PRAW, although there may be some minor differences due to the .ini parser we've used and what we've had a chance to implement.

If you have any more issues, please feel free to ask us through GitHub issues or our Gitter chat and I'll get back to you ASAP.

from draw.

Ivaskuu avatar Ivaskuu commented on September 21, 2024

Excuse me, @bkonyi, but in your example, reddit.auth doesn't have a an url() or authorize() method..
Upon further investigation, I've discovered that Reddit.auth returns an Authenticator object, and not a WebAuthenticator. I've tried messing with WebAuthenticator but can't understand how to instance it or make it work... :(

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

I'm guessing you're using an IDE like Intellij or Visual Studio Code? If so, you might see the errors under those lines (I should update the base Authenticator to have url() and authorize() which throw an unsupported error for other authentication types). Reddit.createInstance() returns an Authenticator, which is a super-type of ScriptAuthenticator, ReadOnlyAuthenticator, and WebAuthenticator, so you should just need a typecast here.

Doing the following should work:

// Putting a type on the left-hand side will cast the `Authenticator` into a `WebAuthenticator`.
// You could also do `(reddit.auth as WebAuthenticator).url()`, but that gets messy if you need to do it
// more than once.
final WebAuthenticator auth = reddit.auth;

// Build the URL used for authentication. See documentation for `WebAuthenticator` for parameters.
final auth_url = auth.url(['*'], 'foobar'));

// ...
// Complete authentication at `auth_url` in the browser and retrieve the `code` query
// parameter from the redirect URL.
// ...

// Assuming the `code` query parameter is stored in a variable `auth_code`, we pass it to the
// `authorize` method in the `WebAuthenticator`.
await auth.authorize(auth_code);

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Sorry for commenting on this long closed issue, but I wanted to let you know that I struggled with the same question and could not find any documentation on the error. When chosing the type "installed app", you dont have a secret, yet there is no constructor in DRAW that doesnt contain a secret except for the UntrustedReadOnlyIntstance. I ended up solving this issue like this:

`

// Create a Reddit instance using a configuration file in the
// current directory.
_reddit = await Reddit.createWebFlowInstance(
  clientId: client_id,
  clientSecret: "", //not null, but empty string
  userAgent: userAgent,
  redirectUri: Uri.parse(redirect_url),
);

`

but I would much rather prefer having a dedicated constructor that does the same. What do you think?

(By the way, using draw: ^0.4.6+1)

Ah, this must have been an oversight on my part when I made individual static methods for each authentication type to replace the catch-all createInstance method. I'll add a createInstalledAppInstance method which does what you suggest. Thanks!

from draw.

naiveai avatar naiveai commented on September 21, 2024

@bkonyi Really sorry for annoying you, but there doesn't appear to be this - does the empty client secret thing still work?

from draw.

StefanLobbenmeier avatar StefanLobbenmeier commented on September 21, 2024

Hi :) putting an empty client secret ("") still works for me.

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Obviously there's still some confusion here, so I'll reopen this issue. @StefanLobbenmeier, @naiveai what's the use case you have? What's the expected behavior?

from draw.

naiveai avatar naiveai commented on September 21, 2024

The use case is to use DRAW in a Flutter app, using the installed app type in Reddit's app registration. There is no secret provided to us when doing this, so we have to simply pass it in as empty when creating a Reddit instance. I ended up doing that and it worked, so all it needs at this point is a dedicated constructor that passes in clientSecret: '' to reduce confusion.

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Hm, I totally thought I had covered this case... anyway, I'll add a proper way to initialize for an installed application type.

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Reddit.createInstalledFlowInstance will be available as of version 0.5.2 which I'll likely release today.

from draw.

naiveai avatar naiveai commented on September 21, 2024

Minor problem, restoreAuthenticatedInstance still requires clientSecret. But eh, that's really not much. Thanks for updating DRAW, and for the support you provide!

from draw.

StefanLobbenmeier avatar StefanLobbenmeier commented on September 21, 2024

from draw.

naiveai avatar naiveai commented on September 21, 2024

@StefanLobbenmeier the client secret doesn't exist with installed apps, so I'm not sure what you mean here.

from draw.

bkonyi avatar bkonyi commented on September 21, 2024

Minor problem, restoreAuthenticatedInstance still requires clientSecret. But eh, that's really not much. Thanks for updating DRAW, and for the support you provide!

Whoops, totally forgot about that! Thanks for pointing it out, I'll update things :)

from draw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.