[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-user
Subject:    Re: [Gambas-user] Request.Header and Base64Decode for a CGI
From:       Benoit Minisini <gambas () users ! sourceforge ! net>
Date:       2009-01-14 21:23:43
Message-ID: 200901142223.43731.gambas () users ! sourceforge ! net
[Download RAW message or body]

On mercredi 14 janvier 2009, Toni wrote:
> Hi,
> I'm programming a CGI using Gambas2 and I want to implement "basic http
> authentication" into it, but I have two problems to get it done: I Don't
> know how to get Request HTTP Headers (I couldn't find something like
> "Request.Header[]"). The other problem is that I haven't been able to
> find a decoding Base64 function in Gambas. Is there one?
>
> Here is a sample code of how I wanted to implement it:
>
>
> PRIVATE SUB Authorize()
>   DIM Validated AS Boolean = FALSE
>   DIM User AS String = "user"
>   DIM SecretPassword AS String = "secret"
>
>   IF Request.Header["Authorization"] <> "" THEN '<-----------
> Request.Header IS AN INVETION
>        IF base64_decode(Request.Header["Authorization"]) == (User & "+"
> & SecretPassword) THEN Validated = TRUE '<--------- base64_decode IS AN
> INVETION TOO
>   ENDIF
>
>   IF (NOT Validated) THEN
>     Response.AddHeader("WWW-Authenticate", "Basic realm=\"AgendaXML-WEB\"")
>     Response.AddHeader("status", "401 Unauthorized")
>     Response.Begin
>     Response.End
>     QUIT
>   END IF
> END
>
>
> Regards,
> Toni
>
> PS: I guess I could use the web server authentication mechanisms but I
> just wondered whether I could control it from within my CGI
>

You can't control HTTP authentification from the CGI script. The server must 
handle it, and you will get the result in the CGI["AUTH_TYPE"] and 
CGI["REMOTE_USER"] environmental variables.

Regards,

-- 
Benoit Minisini

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic