Skip to content

403 (Forbidden) despite valid Client ID, Secret and Refresh Token #185

Description

@janssen-io

For a couple years now, I have a bot running smoothly thanks to this library.
Unfortunately, since a few days now I started seeing 403 - Forbidden errors.

When troubleshooting using Fiddler, I found out that the token refresh in Reddit.Models.Internals.Request is never being hit.
My hunch is that Reddit used to respond with 401 - Unauthorized and changed this. Now the conditional on line 174 is no longer true and thus the Access Token stays null.

When I change the conditional to include || (res.StatusCode == HttpStatusCode.Forbidden, the app works as expected again. :)

        private IRestResponse GetResponse(IRestResponse res, ref RestRequest restRequest)
        {
            int serviceRetry = 3;
            do
            {
                int retry = 5;
                while ((res == null || !res.IsSuccessful)
                        && (RefreshToken != null || DeviceId != null)
                        && (res.StatusCode == HttpStatusCode.Unauthorized  // This is returned if the access token needs to be refreshed or wasn't provided.  --Kris
                       ---> || res.StatusCode == HttpStatusCode.Forbidden  // Since 2024-07 it seems that Reddit returns Forbidden instead of Unauthorized when no token is present. --janssen-io (Stan)
                            || res.StatusCode == HttpStatusCode.InternalServerError  // On rare occasion, a valid request will return a status code of 500, particularly if under heavy load.  --Kris
                            || res.StatusCode == 0)  // On rare occasion, a valid request will return a status code of 0, particularly if under heavy load.  --Kris
                        && retry > 0)
                {
                     // ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions