Skip to content

Add support for /auth-check  #2466

@Wauplin

Description

@Wauplin

Related to huggingface/datasets#7110.

We have a endpoint to check a given user/token has access to a repo: GET /api/{repo_type}s/{repo_id}/auth-check". It's especially useful to check permissions on a gated repo. Let's add a auth_check method to HfApi based on datasets implementation:

def check_auth(hf_api, repo_id, token=None):
    headers = hf_api._build_hf_headers(token=token)
    path = f"{hf_api.endpoint}/api/datasets/{repo_id}/auth-check"
    r = get_session().get(path, headers=headers)
    hf_raise_for_status(r)

If the user don't have access, a RepoNotFound or GatedRepoError error should be raised.
Need to add a proper docstring and tests as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions