Skip to content

add curl's ANY and ANSAFE authorization options#1187

Merged
COM8 merged 2 commits intolibcpr:masterfrom
hyOzd:feature/auth-mode-any
Feb 24, 2025
Merged

add curl's ANY and ANSAFE authorization options#1187
COM8 merged 2 commits intolibcpr:masterfrom
hyOzd:feature/auth-mode-any

Conversation

@hyOzd
Copy link
Contributor

@hyOzd hyOzd commented Feb 23, 2025

Implements #1184

ANY lets curl determine the correct authentication method. ANYSAFE is
similar but it eliminates the 'BASIC' option.

Some SOAP servers do not reply to authentication requests if content
of the initial request is empty. When ANY option is selected curl
sends initial request with full contents, which allows authentication
process to work.
@hyOzd
Copy link
Contributor Author

hyOzd commented Feb 23, 2025

I actually wanted to refactor Session::SetAuth a bit to reduce code duplication. Not sure if that would be desired?

@COM8 COM8 linked an issue Feb 24, 2025 that may be closed by this pull request
Copy link
Member

@COM8 COM8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyOzd thanks! LGTM

@COM8
Copy link
Member

COM8 commented Feb 24, 2025

I actually wanted to refactor Session::SetAuth a bit to reduce code duplication. Not sure if that would be desired?

What exactly are your plans?
If you got a good idea, you are always welcome to refactor it.
Nevertheless, I would suggest doing this in a follow-up PR if possible so we follow the rule, one PR per change.

@hyOzd
Copy link
Contributor Author

hyOzd commented Feb 24, 2025

void Session::SetAuth(const Authentication& auth) {
    long auth_flag;
    // Ignore here since this has been defined by libcurl.
    switch (auth.GetAuthMode()) {
        case AuthMode::BASIC:
            auth_flag = CURLAUTH_BASIC;
            break;
        case AuthMode::DIGEST:
            auth_flag = CURLAUTH_DIGEST;
            break;
        case AuthMode::NTLM:
            auth_flag = CURLAUTH_NTLM;
            break;
        case AuthMode::NEGOTIATE:
            auth_flag = CURLAUTH_NEGOTIATE;
            break;
        case AuthMode::ANY:
            auth_flag = CURLAUTH_ANY;
            break;
        case AuthMode::ANYSAFE:
            auth_flag = CURLAUTH_ANYSAFE;
            break;
    }

    curl_easy_setopt(curl_->handle, CURLOPT_HTTPAUTH, auth_flag);
    curl_easy_setopt(curl_->handle, CURLOPT_USERPWD, auth.GetAuthString());    
}

Something like that. But I don't think it is worth opening a separate PR.

@COM8 COM8 merged commit 16c5e26 into libcpr:master Feb 24, 2025
42 of 44 checks passed
@COM8
Copy link
Member

COM8 commented Feb 24, 2025

Ah, I see. If you want, you can make a minimal PR with it. It would be a good amount of cleanup.

Else I will try to take care of it eventually.

@COM8 COM8 added this to the CPR 1.12.0 milestone Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support for curl anyauth

2 participants