turnage / graw

Golang Reddit API Wrapper
MIT License
286 stars 50 forks source link

Support for userless authentication #45

Closed bogatuadrian closed 5 years ago

bogatuadrian commented 5 years ago

graw doesn't seem to support Application Only OAuth (as described in the reddit OAuth doc) for "read-only" "user-less" access to the reddit API.

This should be made possible by allowing empty username and password in the reddit.App struct and using golang.org/x/oauth2/clientcredentials for 2-legged OAuth authentication in appClient's authorize method if the Username and/or Password fields are not provided.

I can make a pull request if you agree this feature should be added. I will probably fork graw anyway because I need this feature for a project.

Thanks

turnage commented 5 years ago

I looked at your changes and I would accept a PR if you'd like to share them upstream. The only thing I'd like to add is an error if username or password are set, but not the other. Thank you for opening an issue!

bogatuadrian commented 5 years ago

@turnage Is it OK to return the error from the authorize() method? I would have liked it to be further up the stack, but I can't find a good place for it (mostly because configured() returns a boolean and I don't want to change too many things).

bogatuadrian commented 5 years ago

@turnage It could be cleaner and better for testing to refactor configured() bool to validate() error and return appropriate validation errors. What do you say?

turnage commented 5 years ago

Yeah iirc that doesn't change the public API so sounds totally fine.

bogatuadrian commented 5 years ago

Yeah, it is un-exported and called only in one place (except for a test).

bogatuadrian commented 5 years ago

PR https://github.com/turnage/graw/pull/46 aims at providing the discussed feature.

turnage commented 5 years ago

Merged! Thank you for upstreaming your changes!