LANSA Web API with Basic Authority - User / Password

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Joerg Hamacher
Posts: 124
Joined: Thu Feb 11, 2016 12:01 am

LANSA Web API with Basic Authority - User / Password

Post 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
User avatar
Dino
Posts: 477
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

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

Post 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 14875 times
you get this sample code:
webapibasicauthority02.jpg
webapibasicauthority02.jpg (105.79 KiB) Viewed 14875 times
webapibasicauthority03.jpg
webapibasicauthority03.jpg (100.38 KiB) Viewed 14875 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
Joerg Hamacher
Posts: 124
Joined: Thu Feb 11, 2016 12:01 am

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

Post by Joerg Hamacher »

Hi Dino,

thank you very much for this information and best regards!

Joerg
Post Reply