Generating Session ID and api authentication

To all Wappler wizards and wappler team members, we have been presented an opportunity to build a help and support desk system using wappler and need some help regarding a few things.

We need to authenticate a user by an api, so login with a username and password to this api, which will return a SID(Session ID) All subsequent api calls we will need to pass this SID in order for it to work for that specific user. How to store this SID in a global variable for use in the other api calls once the user is authenticated?

Just a bit in the dark on about doing this correctly, as I have played databases and such but not sure on how to do this via an API. If some examples and explanations could be presented it would be very helpful :slight_smile:

Assuming you are using server side API calls, just set a session variable

Define it in globals

image

The use set Session (Core Actions) to assign it’s value

image

If using client side APIs (not recommentded if you can use server side) then I guess a cookie would do the job

2 Likes

I’d highly recommend doing this on the server, otherwise the session id (which you would have to store on the client) could be easily modified.

Make a call to your 3rd party API, and when you get the session id back, store it in a session variable as @Hyperbytes describes. Once stored, be sure to pass it to all subsequent calls to the 3rd party API.

@Hyperbytes @niall_obrien Thank you very much for the suggestions. Once we get the API details etc. I will give feedback on how its coming along and any problems and relevant questions I have. :slight_smile:

@Hyperbytes Stupid question here but would like your input, How would one display that session variable that is set server side to display on the page for testing purposes initially while developing? :slight_smile:

just assign the value of the session variable to a standard variable.(core actions => set value I.e. . set value mylar = $_SESSION.variablename and check output to make it available to app connect picker

Won’t it be necessary to use PHP to display the session value?

@TomD you can use PHP directly but returning a copy of it as a variable from the server action is easier as it makes it available in the picker within app connect so no need to edit in PHP code. Much easier for the non technical as it is all done in wappler, no coding knowledge needed.

Just tag a line at the end of your server action like this:

image

1 Like

Thanks @Hyperbytes - that’s a useful tip. It was the point about the copy of the session variable I missed. So it would be something like:

image
… and then myVar will be available in AppConnect.

2 Likes

BUT i have added a feature request as it would be much easier if Server Sessions were available direct form App connect, get voting!

2 Likes

Very good idea. It’s certainly caused me confusion in the past.

@Hyperbytes Thank you for the feature request! I’m sure more people than myself will definitely benefit from this :slight_smile: I’m currently stuck at this point:

I’m trying to apply the ‘Bearer token_xxx_xx’ dynamically like so, it works as required in the IDE(Wappler app), displays the data in the IDE with dynamic data picker that I choose.

headerDynamic

but not in the browser because the dynamic data picker doesn’t pull through when I open up the ‘Define API Schema’ and thus, cant authenticate the API to display the data in the browser

dynamicSchema

Any help regarding this, How to apply a dynamic value i.e {{SID.value}} to appear in the API Schema header as shown? Just new at working with dynamic values like this :slight_smile:

If you need my workflow of how I achieved this I can also elaborate further.

With a dynamic value it will not show in that screen as wappler does not have a value to extract, you will have to enter the value manually to fetch the schema. It will then work correctly in the live environment. If you are trying to define the schema, juts enter the value manually, click Fetch schema and save
Once you have the schema then it ceases to be a problem

1 Like