1. Thomas Rolseth
  2. SnapDevelop
  3. Friday, 24 January 2020 14:25 PM UTC

I have setup JWT Authentication in our SnapDevelop Web API using this as a guide:

https://docs.appeon.com/appeon_online_help/snapdevelop2019/Secure_a_Web_API_with_JWT_Token/index.html

It seems to be working well so far and I am getting a token back when I call GetJWTToken() in the client app.  I have also set a custom request header in our client application as part of JWT Authentication like so:

lnv_RestClient.SetRequestHeader("ID", "123456")

Let's say the user logs in successfully and then makes some service method calls via a controller. How do
I access that request header value in a
service method? I've tried var id = Request.Headers["ID"] but it doesn't
understand the 'Request' directive. Is there a 'using' reference I need to add? We are using Serilog and I
am hoping to capture unique values
from the client to use in our logs. Mainly I am looking for a way to set and
store value that persist as the user makes various API calls from the PB client.

The user might even open two instances of the PB client app. In this case the userid would be the same but
how could I tell them apart in the log? I've looked at InMemory caching - both native and outside frameworks
like Redis. Setting a cache value seems to be easy but successfully retrieving it is giving me problems.

Thanks, Tom


Thomas Rolseth Accepted Answer Pending Moderation
  1. Tuesday, 28 January 2020 17:37 PM UTC
  2. SnapDevelop
  3. # 1

In our PB client app, I set a request header like so:

RestClient g_APIClient
g_APIClient = Create RestClient
g_APIClient.SetRequestHeader("SesssioID", g_session_id)

In our SnapDevelop API, I added the code below to one of our controllers: 

                            Microsoft.Extensions.Primitives.StringValues sid;
                            var re = Request;
                            var headers = re.Headers;
                            bool requestHdr = headers.TryGetValue("SessionID", out sid);  
                            if (requestHdr)
                            { 
                                Log.Information("SessionID = " + sid);                                
                            }

The value for 'sid' is always blank though.  I debugged the PB client app and know that g_session_id has a valid value.  Does request header info set in a PB client app really get sent over the wire to the API?  If so, what am I missing here?  Any suggestions on how to capture and use a custom request header value?

Thanks, Tom

Comment
  1. Arnd Schmidt
  2. Wednesday, 29 January 2020 00:36 AM UTC
Is there a typo? SesssioID vs SessionID?
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.