Comments (15)
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.
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.
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.
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.
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.
@bkonyi Really sorry for annoying you, but there doesn't appear to be this - does the empty client secret thing still work?
from draw.
Hi :) putting an empty client secret ("") still works for me.
from draw.
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.
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.
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.
Reddit.createInstalledFlowInstance
will be available as of version 0.5.2
which I'll likely release today.
from draw.
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.
from draw.
@StefanLobbenmeier the client secret doesn't exist with installed apps, so I'm not sure what you mean here.
from draw.
Minor problem,
restoreAuthenticatedInstance
still requiresclientSecret
. 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)
- Some questions regarding authentication. HOT 3
- No field for rewarder karma HOT 1
- Cast error on vote
- Subreddit Submit Unhandled Exception: type '_InternalLinkedHashMap<String, String?>' is not a subtype of type 'Map<String, String>' in type cast HOT 4
- Some tests for this package fail in sound null-safety mode HOT 6
- Investigate web authentication test failure HOT 1
- Good way to get only comments HOT 3
- Bugs with comment api. HOT 1
- TypeError when accessing "variants" property of "Submission" object HOT 2
- Get other information such as icon_img HOT 1
- how to get subreddit icon like in PRAW HOT 2
- Redirect doesn't work? HOT 1
- SubredditRef promotion to Subreddit HOT 1
- Getting the authenticated user's subreddits, no `after` param?
- Next release? HOT 1
- Invalid OAuth response for "https://www.reddit.com/api/v1/access_token": required parameter "error" was not a string, was "400". HOT 5
- Unhandled Exception: LateInitializationError: Field '_infoPath@xxxxx' has not been initialized.
- "The authorization URL has not yet been generated." after auth.authorize
- submit media HOT 4
- Search by keyword
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draw.