Get an Oauth2 Token in a Command Line Program

Argggh. I just damaged the token that I had in my configuration.

I forgot how I got it in the first place; I probably used some small program that used the web browser, or I got it from the developer site, or something. I really don’t remember.

What’s the Problem?

A web app using OAuth2 delegates the login process (and application permissions) to an OAuth2 server. Usually, this is Google, Twitter, or Facebook. You see the “Login with…” buttons.

When you are joining or logging onto a site, you see those buttons. You click on one, and get a window or dialog with the external service. You perform the logon, and then return to the original site.

The OAuth2 application flow involves showing a web page to the user, and getting a redirect URL back to the application. The redirect contains an access token. We need to get that token.

Microsoft services have a Python library to do the magic. It’s called MSAL (previously ADAL). https://learn.microsoft.com/en-us/information-protection/develop/concept-authentication-acquire-token-py

I need something like that for Ebay. Fortunately Ebay has libraries for this.

Okta has an interesting example: it runs an HTTP server that interacts with the Oauth2 server. https://developer.okta.com/blog/2018/07/16/oauth-2-command-line

Here’s another Okta post about it. These articles are so instructive. https://developer.okta.com/blog/2018/12/13/oauth-2-for-native-and-mobile-apps

IBM products have their own tech https://www.ibm.com/docs/en/cloud-paks/cp-biz-automation/19.0.x?topic=io2pa-how-command-line-application-obtains-access-token-from-ums

https://github.com/burnash/gspread/wiki/How-to-get-OAuth-access-token-in-console%3F/7a78ebc5fcc17827c1f4311a409ffdeca398a281

https://developers.google.com/identity/protocols/oauth2

https://stackoverflow.com/questions/60662197/oauth2-access-token-in-console-application

https://www.bing.com/videos/search?q=script+to+get+oauth2+token+from+console&docid=608037859205193313&mid=3A7D9348CBCE4988A1513A7D9348CBCE4988A151&view=detail&FORM=VIRE

https://stackoverflow.com/questions/38494279/how-do-i-get-an-oauth-2-0-authentication-token-in-c-sharp

https://stackoverflow.com/questions/38494279/how-do-i-get-an-oauth-2-0-authentication-token-in-c-sharp

https://gist.github.com/modder2/09caaef602ddf30db5bb417398aa7cae

https://gist.github.com/clarketm/dc5d5be390e3f811a2dd7f5e8c5728ba

How to Authenticate using Keys, BasicAuth, OAuth2 in JavaScript