Re: Doing basic authentication

> I'm writing a very simple HTTP 1.1 client Windows using libwww.  I need
> to handle basic authentication.  My app has no user interface and every
> request will have the same authentication.  After browsing through the
> code, documentation and examples, here's what I think I need to do.  I'd
> appreciate it very much if someone would let me know if I'm on the right
> track or way off base.
>
> I'm using a default profile so HTCredentialsFilter is registered for
> me.  I think all I need to do is call HTRequest_addCredentials() for
> every request.  I'll generate the arguments using code borrowed from
> BOOL basic_credentials() as found in HTAABrow.c.

Marco,

    I don't know if you are on the right track or not,
    but another thing you can do that can be a little easier is
    to declare your application as interactive, implement all the
    callbacks for user interaction as returning no data, and
    implemente the callback for the user and password request to
    return your fixed data.

    Here is a quick example for such a callback:

        PUBLIC BOOL prompt_callback (HTRequest * request, HTAlertOpcode op,
                       int msgnum, const char * dfault, void * input,
                       HTAlertPar * reply)
        {
            if (op == HT_A_USER_PW) {
                HTAlert_setReplyMessage(reply, my_user);
                HTAlert_setReplySecret(reply,  my_password);
                return YES;
            }

            /* we are really NOT that interactive */
            return NO;
        }

    And you can register the callback in your application initialization code:

        HTAlert_setInteractive(YES);
        HTAlert_add(prompt_callback, HT_A_CONFIRM);
        HTAlert_add(prompt_callback, HT_A_PROMPT);
        HTAlert_add(prompt_callback, HT_A_SECRET);
        HTAlert_add(prompt_callback, HT_A_USER_PW);

Hope this helps,

    Raffaele

Received on Thursday, 17 June 1999 18:05:56 UTC