Invalid client in django-oauth-toolkit v2 that was valid in v1

  Kiến thức lập trình

I’m running seasonal upgrades on a project and noticed django-oauth-toolkit stayed a 1.7.1 last time.

The upgrade to 2.x turns two tests from 200 to 401, invalid_client.

One of these tests looks like this;

@pytest.fixture
def oauth_data(db):
    test_region = Region.objects.create(
        name="MyRegion", iso_code_short="MYR", iso_code_long="MYREG"
    )
    app_owner = USER_MODEL(
        username="app-owner",
        email="[email protected]",
        gender="M",
        date_of_birth="1970-1-1",
        region=test_region,
        first_name="John",
        last_name="Doe",
    )
    app_owner.set_password("password")
    app_owner.save()

    app_redirects = "http://site1.com/returnrnhttp://site2.com/back"
    app = Application.objects.create(
        name="My Test Client",
        client_id="test-app",
        client_secret="password",
        client_type=Application.CLIENT_CONFIDENTIAL,
        authorization_grant_type=Application.GRANT_PASSWORD,
        user=app_owner,
        skip_authorization=True,
        redirect_uris=app_redirects,
    )
    return {"app": app, "app_owner": app_owner}


# some test class here...

    def (
        self, oauth_data, client, settings
    ):
        mixin = AccessTokenGeneratorMixin()
        tokens = mixin.get_access_token(oauth_data["app"], oauth_data["user"])

        url = reverse("oauth2_provider:token")
        response = client.post(
            url,
            data={
                "client_id": oauth_data["app"].client_id,
                "client_secret": oauth_data["app"].client_secret,
                "grant_type": "refresh_token",
                "refresh_token": tokens["refresh_token"],
            },
        )
        assert 200 == response.status_code

Is there something in v2 (that I’ve missed in the release notes) that invalidates this fixture to create an invalid client!?

LEAVE A COMMENT