[Gambas-user] Request.Header and Base64Decode for a CGI
Toni
arosa at ...2015...
Wed Jan 14 22:37:25 CET 2009
Thanks for such a quick answer!
Toni
En/na Benoit Minisini ha escrit:
> 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,
>
>
More information about the User
mailing list