B4J Question how to use bearer authentication on my own jServer

Discussion in 'B4J Questions' started by Alexander Stolte, Feb 1, 2019.

  1. Alexander Stolte

    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?

  2. DonManfred

    DonManfred Expert Licensed User

    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.

    i dont´see anything problematic in reading a header. Sure it is free
    Last edited: Feb 1, 2019
  3. DonManfred

    DonManfred Expert Licensed User

    Dim j As HttpJob
    "", _
    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"
    "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
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice