iOS Question [SOLVED][B4X] POST authentication with JWT Postman

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
How can I consume this API like I do in Postman. 'Username' and 'password' are required as seen in the image
1606602085778.png


My Code is:
B4X:
Sub Crear_Token
    Dim job As HttpJob
    job.Initialize("",Me)
    job.PostString("https://apify.epayco.co/login?",$""$)
    job.GetRequest.SetHeader("Authorization", "Basic")
    job.Username = "c74c2c0a50c0af64ea17d9810e830ae0"
    job.Password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    job.GetRequest.SetContentType("application/json")
    Wait For (job) JobDone(j As HttpJob)
    Log("Result Token: " & j.Success)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
End Sub
 
Solution
Do you tried also:

B4X:
Dim basicAuth as string = "replacewithyouruser:replacewithyourpassword" '<------ HERE
Dim su As StringUtils 
Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) '<------ HERE
Dim j As HttpJob
j.Initialize("", Me)
..............
j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$) '<--- HERE
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release

josejad

Expert
Licensed User
Longtime User
Maybe this can help?

 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Maybe this can help?

Tried this example but nothing. Also where is the Username?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hum... try something like:

 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Hum... try something like:

a nothing Jose.
I get {"error": "username is required"}.
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Ok, now with this code it detects the username, but it does not detect the password. {"error": "password required"}.
How can I make it detect my password?

B4X:
Dim job As HttpJob
    job.Initialize("",Me)
    job.PostString("https://apify.epayco.co/login?",$""$)
    job.GetRequest.SetHeader("Authorization", $"Basic Username=${username} &Password=${Password}"$)
    job.GetRequest.SetContentType("application/json")
    Wait For (job) JobDone(j As HttpJob)
    Log("Result Token: " & j.Success)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thanks, but where do I put the password?

You didn't read the first lines of the thread sent

Your api key most likely has the following syntax "xxxx: yyyy"

Put your first part ( xxxx ) in j.Username
and the second part ( yyyy ) in j.Password

 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
You didn't read the first lines of the thread sent



Friend, I mean the JWT Basic Authorization request type.
This method doesn't work for me, as you could see in post # 1.
Thank you!
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Do you tried:

B4X:
Dim basicAuth as string = "repalcewithyouruser:replacewithyourpassword" '<------ HERE
Dim j As HttpJob
j.Initialize("", Me)
......
j.GetRequest.SetHeader("Authorization", "Basic " & basicAuth) '<----- HERE
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Do you tried:

B4X:
Dim basicAuth as string = "repalcewithyouruser:replacewithyourpassword" '<------ HERE
Dim j As HttpJob
j.Initialize("", Me)
......
j.GetRequest.SetHeader("Authorization", "Basic " & basicAuth) '<----- HERE
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
Thanks MarcoRome, but I get a response {"error": "password is required."}
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Do you tried also:

B4X:
Dim basicAuth as string = "replacewithyouruser:replacewithyourpassword" '<------ HERE
Dim su As StringUtils 
Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) '<------ HERE
Dim j As HttpJob
j.Initialize("", Me)
..............
j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$) '<--- HERE
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release
 
Upvote 1
Solution

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Do you tried also:

B4X:
Dim basicAuth as string = "replacewithyouruser:replacewithyourpassword" '<------ HERE
Dim su As StringUtils
Dim authInfo = su.EncodeBase64(basicAuth.GetBytes("UTF8")) '<------ HERE
Dim j As HttpJob
j.Initialize("", Me)
..............
j.GetRequest.SetHeader("Authorization", $"Basic ${authInfo}"$) '<--- HERE
Wait For (j) JobDone(j As HttpJob)
If j.Success = True Then
Log(j.GetString)
Else
Log(j.ErrorMessage)
End If
j.Release


Woooo! EXCELLENT THANKS!!!
Problem solved as you have it in this code
 
Upvote 0
Top