Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Aronaman's avatar

integration server

hello guys it is the first time, i need some ideas.

there is a desktop application made using vb and I made a web app, my client wants to integrate the local DB connect with the cloud server.

what I did so far (conceptual)

create API (REST API in .Net ) for desktop application and define endpoints. then i create a restful API for the web app(laravel), then i think every user should have an API key, so i create the column "access_key" inside the user table in laravel then i generate 10 unique random digits and save it inside user table in access_key column for every user, after that i create a middleware "apiKey" check the access key belongs to the user. after that, i define the API route with the middleware.

my question is: #1my method is recommended?? or should I use laravel passport and generate personal access token??, if so where should i save personal access token in laravel ?

#2 the integration planed in both directions so, i should prepare a form in desktop to save the access_key inside the desktop configuration ?? same access_key for same user on web and desktop. on both endpoint e.g https://server.larave/api/create/access_key=As1sdgddfsdrt (it is from desktop to web) and https://desktop/api/4/update/access_key=As1sdgddfsdrt (it is from web to desktop) ??

i know i make it more complex, can any body help me thanks

0 likes
5 replies
automica's avatar

@aronaman having a shared access token is fine. I would pass it in in the headers rather than as part of the url though.

I'm using a static access_token for my api due to it only needing to be accessible by a vue front end. You would want to do something similar to my middleware to check it.

namespace App\Http\Middleware;

use Closure;

class VerifyAPIAccess
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (
            !($_ENV['APP_ENV'] === 'local')
            && (
                !$request->header('access-token')
                || $request->header('access-token') !== env('APP_API_TOKEN')
            )
        ) {
            return response()->json(['Message' => 'You do not access to this api.'], 403);
        }

        return $next($request);
    }
}

and then add it to your group in your api.php

Route::group([
    'prefix' => 'v1',
    'as' => 'v1.',
    'middleware' => [
        VerifyAPIAccess::class
    ]
], function () {
 // protected api routes accessible by api/vi/yourRoute
});

if you are only accessing the Laravel app from your local desktop app, you could additional limit access based on IP address range.

Aronaman's avatar

@automica tnx for the response, but I am asking 2 questions can give me some suggestion, I am not focusing on the code right now, I am lost in the concept part.

is there any documentation for this kind of scenario

automica's avatar

@aronaman for you questions.

  1. I would say just using a unique access_token that you generate for each user is fine. Store it on the user table.

  2. if you want to access both ways, then storing the tokens duplicated at either end is fine. as you are also in control of IP addresses at both ends, you can always limit access to the remote server from a known IP range as an additional security measure.

TBH it may be fine just to have a single shared token between your local and cloud applications. Its not like the client has access to the token or the request so whether its unique per user or 1 per app is fine.

Aronaman's avatar

@automica ok ..what about i use passport "personal access token", the problem I encounter is i don't know how to retrieve and save to desktop config file.

second expired token issue

automica's avatar

@aronaman my understanding of the purpose of using a token is to deal with it rather like you'd use a ssh key to authenticate a user. in that case, you would need to worry about expiring it, as if its part of the request then let them in (like using a door key for your house).

if you are using a key per user, then you could also compare against their email address so only access_key and email gets you in for a user.

I don't think you would need to expire this access token, unless you want to prevent the user from no longer accessing your app (like handing your doorway in when you move house).

if you are also limiting with firewall rules, then you are even more secure.

Please or to participate in this conversation.