OAuth2 help getting token

Hello,
I’m trying to figure out how to use OAuth2 in Wappler and I’m having some issues…
I followed Using OAuth2 Connector with Facebook and had no problems there but now that I’m trying to connect to a custom service it’s not the same.

They provide a how to get started guide showing how to get the access token but I don’t know how to do that using Wappler’s tools…

Here’s what they provide:

<?php

function getAccessToken(): String
{
    $authUrl = "https://allegro.pl.allegrosandbox.pl/auth/oauth/token?grant_type=client_credentials";
    $clientId = "...";
    $clientSecret = "...";

    $ch = curl_init($authUrl);

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERNAME, $clientId);
    curl_setopt($ch, CURLOPT_PASSWORD, $clientSecret);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $tokenResult = curl_exec($ch);
    $resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($tokenResult === false || $resultCode !== 200) {
        exit ("Something went wrong");
    }

    $tokenObject = json_decode($tokenResult);

    return $tokenObject->access_token;
}

function main()
{
    echo "access_token = ", getAccessToken();
}

main();

So I created an OAuth Provider:


and used it in an action:

but when I open that in the browser I’m getting a login alert
image
which I don’t think is supposed to happen but putting in my login details just makes the window reappear

I know I could just use plain php but I’m not really familiar with it and I’d rather use server actions…
Any nudge in the right direction will be appreciated :slight_smile: