r/redditdev • u/kemitche ex-Reddit Admin • Dec 10 '14
[OAuth2] Implicit grants, CORS, & app-only OAuth2
Greetings!
reddit now supports the OAuth2 implicit grant flow, which means you should now be able to create front-end only, JavaScript web apps that access reddit's APIs. The reddit OAuth2 docs have been updated with information on the flow (and, of course, please provide suggestions for documentation improvements here).
Note: Only apps created as "installed" type apps may use the implicit flow. "web" and "script" type apps are considered "confidential" (i.e., they have secrets). Since you cannot safely send a secret via the implicit flow, we have elected to disallow implicit access to apps with secrets.
CORS restrictions on OAuth2 requests have been loosened to allow for this. Non-oauth2 CORS restrictions are unchanged.
Also, reddit now supports 2 methods for accessing OAuth2-only APIs without actually logging in as a user: We've implemented the "client_credentials" grant (for confidential clients) and created a similar extension grant (for non-confidential clients). Again, the reddit OAuth2 docs have been updated with more info.
The two primary advantages of application-only OAuth2 access to the reddit API are:
- User-less access to OAuth2 only APIs, such as trophies
- Simplification of your application code - all your standard API requests can go to the same domain, oauth.reddit.com, always using an
Authorizationheader.
4
u/calebkeith Dec 10 '14
Are we still waiting on mods, banned users, approved submitters, etc. management? It would be very nice to have 😊
2
u/berbaquero Dec 16 '14 edited Dec 16 '14
This is great news! I've been wanting to add user-related stuff to my reddit web-app client for a while.
I have a question: will I need to sent my requests exclusively through HTTPS? — I'm hosting the client-side only web-app on GitHub Pages and the domain is HTTP only. Will that be a obstacle for me?
Edit: Also, would be nice to have an example of a JavaScript, client-side wep-app access to the OAuth2 API in the docs. :)
Thanks!
2
u/42someone Dec 17 '14
I still have the CORS issue when try to get access token from browser. The browser do a preflight request (OPTIONS), and reddit response Unauthorized. Please help
2
u/IdStillHitIt Dec 19 '14
I keep trying and re-reading documentation but I can't get authentation to work, I go to this url: https://www.reddit.com/api/v1/authorize?client_id=sJfMpzP9657BQQ&response_type=token&state=d897kjj39&redirect_uri=http://domenicroti.com/redditv2&scope=identity and I just keep getting an error=invalid_request. Any idea on what's happening?
2
u/toja92 Dec 21 '14
Will it be possible to request an access token that is permanently valid in the future? Or request a refresh token instead?
I'd like to try and do a reddit client that is run entirely in a web browser, but I'd like to avoid having the users reauthorize the client every hour. One obvious solution is to have a server that merely handles all refresh tokens and have the client request a new bearer token once it expires, but then it wouldn't be run entirely in the client's browser.
Or perhaps it's possible right now (and I just missed something in the documentation)?
4
u/Mustermind Dec 10 '14