Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the token mandatory? #840

Closed
MrArturGar opened this issue Feb 3, 2025 · 2 comments
Closed

Why is the token mandatory? #840

MrArturGar opened this issue Feb 3, 2025 · 2 comments

Comments

@MrArturGar
Copy link

I recently wanted to add NGitLab to my project but ran into an issue where the GitLabCredentials constructor enforces a mandatory API token:

public GitLabCredentials(string hostUrl, string apiToken)
{
    if (string.IsNullOrEmpty(hostUrl))
        throw new ArgumentException("HostUrl is mandatory", nameof(hostUrl));
    if (string.IsNullOrEmpty(apiToken))
        throw new ArgumentException("Token is mandatory", nameof(apiToken));

    ValidateHostUrl(hostUrl);

    HostUrl = GetApiUrl(hostUrl);
    _apiToken = apiToken;
}

However, looking at this condition in HttpRequestor.GitLabRequest.cs, it seems that requests without a token are actually supported:
GitLabRequest.cs#L51

Is this an oversight, or is the token intentionally required in GitLabCredentials? If requests can be made without a token, would it make sense to allow GitLabCredentials to accept a null or empty token?

@Toa741
Copy link
Contributor

Toa741 commented Feb 4, 2025

Hello,
It's probably some code put in place a long time ago. As most API request requires to be authenticated, maybe it has just been made to correlate that.

Though, it's technically valid that you would want to do some requests without authentication and the option should be available.

If you want, you can contribute to the project and make a pull request to add it. Otherwise, we will try to make the change as soon as we can.

@MrArturGar
Copy link
Author

I apologize, just now saw the change on my ticket. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants