sirkris / Reddit.NET

A Reddit API library for .NET Standard with OAuth support. Written in C#.
MIT License
505 stars 78 forks source link

Is authentication a must, even if you only want to read public posts? #171

Open HubKing opened 1 year ago

HubKing commented 1 year ago

The constructor of RedditClient has every parameter defaulting to null, so I thought all were optional, including authentication. But the following code threw an exception "403 forbidden". To use this library, must I authenticate?

        var r = new RedditClient();
        var sr = r.Subreddit("cats");
        var top = sr.Posts.Top[0];
sirkris commented 1 year ago

This is a known issue and it relates to how the Reddit API handles oAuth. Basically, if you're using oAuth (which Reddit.NET does for security reasons), then only a very limited number of public endpoints will actually work. You can find a more detailed explanation of the problem here:

https://stackoverflow.com/questions/42009024/reddit-api-returns-http-403

The solution would be to refactor Reddit.NET to withhold the Authorization header when no tokens are provided. It's on my TODO list. For now, though, app-only authentication support with Reddit.NET is currently limited.