Help understanding api

Hello, I am attempting to self manage oauth, I want to post a code state from client side to server side. The server action for this working great when I enter the code manually to test but I don’t understand how pass the code dynamically.

Do I need to use an api action and use query parameter of “code”?

image

image

It says load here, will this run the post?

And invoke the load run/ like this from javascript is okay?

function handleOpenURL(url) {
    setTimeout(function () {
        var queryString = url
        var urlSet = new URL(queryString);
        var urlState = urlSet.searchParams.get("state");
        var urlCode = urlSet.searchParams.get("code");
        if (urlState == 'xxxxx') {
            dmx.parse("apiCodeExchange.load({code:'" + urlCode + "'})");
        }
    }, 0)
}

Hi @fdgfdgfdg, where are you getting the code value from?

If you want to send a variable from client-side to server-side, the best way I’ve found is with a server connect form. You can dynamically add your code value to the value of a hidden form field and submit that to the server for use as a POST variable.

2 Likes

Hi, the code is returned from authorisation url redirect back into my app.
Thanks for the tip about the form, since the code is automatic without user interaction to submit I used a get parameter and it worked fine.

I’m having another issue trying to exchange the code for an access token with snapchat. It works fine with postman, manually inserting the code I get from passed via the Wappler api action to my server.
Everything is the same, I can’t figure it out why it doesnt work, maybe some parsing issue or how I am concatenating the get parameter at the end…

Do you happen to see anything wrong with this?

'https://accounts.snapchat.com/accounts/oauth2/token?client_id=02ffd3b4-fa6e-4c84-b363-38aa65122385&client_secret=xxxxx&redirect_uri=xxxxx://snapkit&grant_type=authorization_code&code='+$_GET.code

@patrick

The schema is the same I copied from there too

{
    "access_token": "xxx",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "xxx",
    "scope": "https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar https://auth.snapchat.com/oauth2/api/user.display_name"
}

I have output selected
image

And trying to insert into database like this
image

But it’s left empty while the code is inserted

I think it’s because of max length on field :sweat:

ok that wasnt the issue either

image

I tried to insert the returned scope data, it does the same so most likely an issue of how i’m constructing the token post url with code in Wappler … needs to be prepared differently.

Or maybe some header is needed?

I am using accept & connection

Bump