B4J Question how to use bearer authentication on my own jServer

Alexander Stolte

Well-Known Member
Licensed User
Hey, I'm writing an API for my app and while analyzing other APIs I've noticed that many are doing the authentication with oauth.

My question is how can i do a "bearer authentication" for my own jServer and is this free?



Licensed User
My question is how can i do a "bearer authentication" for my own jServer
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim bearer As String = req.GetHeader("Bearer") ' to check just a Bearer Header
    Dim authheadercomplete As String = req.GetHeader("Authorization") ' check authorizationheader
    ' and split authheadercomplete to have only the token afterwards...
Check your database now for any valid token and only go on in request if the token is valid.

and is this free?
i dont´see anything problematic in reading a header. Sure it is free
Last edited:


Licensed User
    Dim j As HttpJob
    j.Download2("", _
    Array As String("title", "the Title", "body", "this is the textbody","topic","general"))
    Dim token As String = "This is a dummystr used as a Token"
    j.GetRequest.SetHeader("Authorization","Bearer "&token )
Inside the Server handler
    Dim bearerhdr As String = req.GetHeader("Authorization")
    If bearerhdr.Length > 7 Then
        Dim token As String = bearerhdr.SubString(7).Trim
        Log("Token from Auth-Header: "&token)
    End If
Result from serverlog
Token from Auth-Header: This is a dummystr used as a Token