Page 1 of 1

LANSA Web API with Basic Authority - User / Password

Posted: Thu Aug 10, 2023 10:02 pm
by Joerg Hamacher
Hi,

I have created a Web API with LANSA that runs with Basic Authority (User / Password - no tokens).

How can I receive the values for user and password that are delivered in the request fpor checking it with the entries in our authorization data base file?

This is the basic definition of the server routine:

Srvroutine Name(GetKatalog) Response(*HTTP #Context)
Define_Com Class(#Com_Home.GetKatalog) Name(#Operation)
* Instanzen von Request- und Response-Arrays definieren
Define_Com Class(#Com_Home.RequestArray) Name(#RequestArray)
Define_Com Class(#Com_Home.ResponseArray) Name(#ResponseArray)
* Zum Auslesen des empfangenen Requests
Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#Reader) Reference(*DEFERRED)
Define_Com Class(#XPRIM_ErrorInfo) Name(#ErrorObject) Reference(*DEFERRED)
Define_Com Class(#PRIM_BOLN) Name(#Found)

Can I retrieve user/password with some #Operation values or how do I do this?

Kind regards,
Jörg

Re: LANSA Web API with Basic Authority - User / Password

Posted: Sat Aug 12, 2023 5:31 am
by Dino
Hi Joerg

If you mark the checkbox to generate security samples, you will get an example of how to get the user and password:
webapibasicauthority01.jpg
webapibasicauthority01.jpg (32.73 KiB) Viewed 14874 times
you get this sample code:
webapibasicauthority02.jpg
webapibasicauthority02.jpg (105.79 KiB) Viewed 14874 times
webapibasicauthority03.jpg
webapibasicauthority03.jpg (100.38 KiB) Viewed 14874 times

Code: Select all

....
If (#Com_Owner.VerifyUsernamePassword( #Context #Operation.Request.Security ))
....

Code: Select all

Mthroutine Name(VerifyUsernamePassword)
Define_Map For(*RESULT) Class(#prim_boln) Name(#Verified)
Define_Map For(*INPUT) Class(#prim_srvm.HttpContext) Name(#Context) Pass(*BY_REFERENCE)
Define_Map For(*INPUT) Class(#com_home.Security) Name(#Security) Pass(*BY_REFERENCE)

If (#Security.HttpBasic.Username.LowerCase *EQ "user")
If (#Security.HttpBasic.Password.LowerCase *EQ "user123")
#Verified := true
Endif
Else
If (#Security.HttpBasic.Username.LowerCase *EQ "administrator")
If (#Security.HttpBasic.Password.LowerCase *EQ "admin123")
#Verified := true
Endif
Endif
Endif

Endroutine

Re: LANSA Web API with Basic Authority - User / Password

Posted: Tue Aug 22, 2023 12:05 am
by Joerg Hamacher
Hi Dino,

thank you very much for this information and best regards!

Joerg