HTTPClient request

1
0
-1

hi there, i need to create a rest call like the example below:

POST /auth/realms/edoc/protocol/openid-connect/token
Authorization: Basic abcdefghilmnopqrstuvz
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=mario&password=XJp45pzH

i'm not sure if it's possible and how to set an authorization header HTTP Basic as requested using a client_id and a client_secret that i own

Here is part of the code i'm using which is missing the auth basic header as requested

httpclient http  
http = create httpclient 

ls_URL = ls_token_uri + '/auth/realms/edoc/protocol/openid-connect/token'
ls_mime = 'application/x-www-form-urlencoded'
ls_parm = 'grant_type=password&username=' + ls_username + '&password=' + ls_password
ls_url = ls_url + '?' + ls_parm

http.SetRequestHeader("Content-Type", ls_mime)
li_ret = http.sendrequest( 'POST', ls_url, '')  
if li_ret = 1 then
    li_rc = http.GetResponseStatusCode()
    if li_rc = 200 then http.GetResponseBody(ls_string)

    ...

any help would be appreciated
tia

Question Tags: 

Answers

Simone Olianti answered HTTPClient request

1
+1
-1

i've finally managed how to handle this. Here is the solution in case someone else having same question

basically to set the http basic authorization i had to crypt the client_id and client_secret in base64 (i.e "client_id:client_secret")
then set a header like this

ls_header = 'Basic ' + ls_encoded
http.SetRequestHeader("Authorization", ls_header)

everything working fine

p.s. also i had to pass the parameters of the call in the body

 

Andrew Davis's picture

2 things hear - can you explain how you converted to base64 

and also how do you pass the parameters of the call in the body

simone@start2.it's picture

Hi Andrew
to pass the parameters in the body:

ls_parm = ls_response_type + '&' + ls_user + '&' + ls_pass
bdata = blob(ls_parm, EncodingUTF8!)
li_ret = ln_http.sendrequest( 'POST', ls_url, bdata) 


to encrypt any string in base64 you can look at this really useful Bcrypt object developed by Roland Smith
http://www.topwizprogramming.com/freecode_bcrypt.html