def METHOD_NAME(old_refresh_token: UUID, session: so.Session):
    """Implements logic for refresh token grant."""
    # check token exists in database and get expire time and user id
    old_token_document = session.execute(
        sa.select(dbm.Refreshtoken).where(
            dbm.Refreshtoken.token == old_refresh_token
        )
    ).scalar_one_or_none()
    raise_if_none(old_token_document, InvalidGrant, "Refresh token is invalid.")
    # check token is not expired
    expire_time = old_token_document.expire_time
    raise_if(expire_time < getnow(), InvalidGrant, "Refresh token is expired.")
    # check user exists
    orm_user = old_token_document.user
    dbm.User.check(orm_user, InvalidGrant, "Refresh token is invalid.")
    # generate token
    access_token = LoadedAccessToken(
        orm_user.id, orm_user.username, orm_user.scope or {}
    ).encode()
    refresh_token = OAuth2.generate_refresh_token(orm_user.id, session)
    # delete old refresh token from database
    session.delete(old_token_document)
    session.execute(
        sa.delete(dbm.Refreshtoken).where(dbm.Refreshtoken.expire_time < getnow())
    )
    return OAuth2.success_response(access_token, refresh_token)