Reputation: 310
I have my authorisation url - https://www.reddit.com/api/v1/authorize?client_id=xuJKekGTr1-V8Q&response_type=code&state=dfDfsd4gdf&redirect_uri=http://localhost:8080/redditimageuploader/callback&duration=permanent&scope=submit
But I don't really know what to do from here? I've found a few guides online but it's just a lot of jargon I don't really understand. When I click on the "allow" button, it takes me to the url that I defined as my redirect_uri
, and appended to the end of the string is the state
that I set, as well as code=
and then a string - so I assume I need to do something with those, but I don't know what.
I was wondering if there is a super simple "explain like I'm 5" step-by-step guide on what to do from here?
Upvotes: 0
Views: 696
Reputation: 2434
It's a standard OAuth flow. From the doc :
https://www.reddit.com/api/v1/authorize
and enriched with the request params you specified. Reddit will then ask the user to sign in, and whether or not he wants to authorise your app access to the requested scope. See https://github.com/reddit-archive/reddit/wiki/OAuth2#allowing-the-user-to-authorize-your-applicationhttp://localhost:8080/redditimageuploader/callback
). Reddit will add a state
request param: you need to ensure that this is the same as the one in your request.https://www.reddit.com/api/v1/access_token
, including the following data in your data: grant_type=authorization_code&code=CODE&redirect_uri=URI
. Replace CODE with the value you received and URI with your same redirect URI as in the first step.
The response to this third step should return you an access token: store this for future requests on behalf of the user. See https://github.com/reddit-archive/reddit/wiki/OAuth2#retrieving-the-access-tokenExtra steps are available and documented for error handling and access token operations (invalidation / renewal).
So, once you've correctly implemented the first step, all you need to do is create an endpoint (the one called when your redirect URI is redirected to) which will :
state
request paramLet me know if this is clear enough.
Upvotes: 1