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

Some questions regarding authentication. #196

Closed
SupremeDeity opened this issue Jul 26, 2021 · 3 comments
Closed

Some questions regarding authentication. #196

SupremeDeity opened this issue Jul 26, 2021 · 3 comments

Comments

@SupremeDeity
Copy link
Contributor

First of all, i have not used a reddit api before.

I want to create a reddit client as practice for creating flutter apps, the questions i have are:

  1. Can i just use "localhost:3000" for the redirect uri.
  2. The part in the example regarding fetching the auth code is left upto the user. I saw a closed issue regarding this which used uni_links and url_launcher. I am going to try using the webview plugin instead. Is this a good idea?
  3. How would i refresh my authentication? How do i check if my auth code expired? Do i just run the refresh method from auth.dart everytime my code expires?

Sorry that some of these come of as a bit noobish but i will keep experimenting and if possible provide a complete example after i am done for those that come looking for it afterwards.

@SupremeDeity
Copy link
Contributor Author

The first two parts have been solved by me:

  1. I have to use deep link/uni-link
  2. I ended up using url_launcher and uni_link

These are some issues i still have:

  1. I still dont know how i can verify my session, instantiate my reddit instance etc.

@bkonyi
Copy link
Member

bkonyi commented Aug 2, 2021

I'll be completely honest, I'm not 100% sure about refreshing authentication tokens. Calling refresh() should do the trick, but when in doubt, referring to the PRAW documentation should get you on the right path (DRAW shares a lot of the same logic as PRAW for authentication). Maybe this will help?

@SupremeDeity
Copy link
Contributor Author

SupremeDeity commented Aug 2, 2021

As a followup to this, for whoever wants to find a answer. This is mainly for Installed Flow:

  1. You should go through my comment and read on the second method. It explains a lot.

  2. After reading on that, look up: url_launcher and uni_links. This is for getting the refresh token for the first time.

  • redirect_url: The url you get redirected to AFTER the authentication on the webpage is completed. This is very important. Read below for more info.

  • url_launcher: For launching the url you got with reddit.auth.url()

  • uni_link: Use the deep link to create a scheme like: myapp://auth, this also needs to be your redirect_url. Uni_link will then catch, whenever you get redirected to this link, and bring you back to the app.

  1. Save the credentials somewhere with SharedPreferences or some other package. I would recommend checking out how its done on the Web Authentication Flow on the readme.

  2. Use the credentials with Reddit.restoreInstalledAuthenticatedInstance() instead of the Reddit.createInstallFlowInstance(). Both these methods return a Reddit Instance.

Note: The credentials contains the refresh token, you need to save the entire credentials.

@bkonyi i would recommend you reference this in your readme in the installed flow section.

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

No branches or pull requests

2 participants