NetTalk Central

Author Topic: 2Step process - Bearer token - OAuth?  (Read 778 times)

JohanR

  • Sr. Member
  • ****
  • Posts: 401
    • View Profile
    • Email
2Step process - Bearer token - OAuth?
« on: September 01, 2025, 08:29:09 AM »
Hi,

Looking to get some JSON data from a 3rd party API server tracking , Fedex

I have to request the bearer token using credentials, and then use the returned bearer token to fetch the data.
The bearer token expires after an hour.

Before I dive in and code the 2 steps , this seems to be exactly the same as OAuth.
Am I on the right path?

Or as simple to code the 2 steps?

thanks

Johan









Jane

  • Sr. Member
  • ****
  • Posts: 409
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: 2Step process - Bearer token - OAuth?
« Reply #1 on: September 01, 2025, 02:24:28 PM »
The one system I've got in production doing that, Johan, I wrote 7+ years ago and did my own thing rather than whatever OAuth was available at that time.
It's been working fine since.
I guess the question would be whether each of your customers has his own credentials, or whether you are contacting the API as you.
I think a lot of the rationale for OAuth is when you're acting on behalf of somebody else.  In my app, that's not the case.

I have two generic procedures:
1. Checks the expiration of my existing token. Fetches a new token if the old one is within 5 minutes of expiry.
2. General API-calling NetTalk client.  It's called by something else.  It gets a token from the check-and-update-if-needed token procedure, then fills a StringTheory object with what's received from the API.

Then I have various procedures for individual API endpoints I need.
Each procedure constructs the URL with its parameters list.  Then passes the URL, a String Theory object, and anything else needed to the api-calling procedure.  When the latter has completed, the procedure parses the String Theory object and does its thing.

I posted more details a while back.
NOTE:  I've fixed this code since then. 
Instead of the custom header I was using in that old post, I now use ThisWebClient.Authorization

Code: [Select]
!    ThisWebClient.CustomHeader = 'Authorization: Bearer '&clip(pToken) !changed to ThisWebClient.Authorization 12/31/2024
    ThisWebClient.Authorization = 'Bearer ' & clip(pToken)

https://www.nettalkcentral.com/forum/index.php?topic=9562.msg39234#msg39234


JohanR

  • Sr. Member
  • ****
  • Posts: 401
    • View Profile
    • Email
Re: 2Step process - Bearer token - OAuth?
« Reply #2 on: September 01, 2025, 09:38:45 PM »
Hi Jane

Thanks for detailed reply as always!

I'm glad to report after reading your reply and method, it's the route I am busy with.
Feels good to know I am on the right path :)

After reading the OAuth docs, I also went the route of doing my own thing.
I've done quite a few different API's but not the 2 step process.
Just seemed more simple and in control than trying to understand the OAuth process.
I'm almost done, so far so good.

All seems pretty simple, and thanks to NT and the Codewriter takes an enormous amount of time, pain and possible mistakes out of it.

thanks

Johan