4D Blog

Home Product 4D Netkit: Enhancement of OAuth2 Authorization

4D Netkit: Enhancement of OAuth2 Authorization

July 19, 2023

Product

With 4D v19 R3, connecting your application to the Microsoft Graph API through OAuth 2.0 has become incredibly convenient using 4D NetKit.

Now, with 4D v20 R2, you can seamlessly obtain an OAuth 2.0 token for Google API or other OAuth 2.0 servers. And even better, to further enhance the integration of this authentication process into your application, we have introduced a feature that allows you to display your HTML page directly in your web browser once the token is received.

Keep reading for all the details!

HDI Connect to GitHub using OAuth 2.0

Prerequisites

Before getting a token from the Google API, the first step is to obtain OAuth 2.0 client credentials from the Google API Console. It establishes a trust relationship between your app and the Google API. Trust is unidirectional: your app trusts the Google API, not vice versa.

This tutorial by Google is an excellent resource for understanding how to use OAuth 2.0 to access Google APIs.

Registration integrates your application with the Google API Console and establishes the information that it uses to get tokens, including:

  • a Client ID: A unique identifier assigned by the Google API Console.
  • a Redirect URI/URL: One or more endpoints where your app will receive responses from the Google API Console.
  • a Client Secret: A secret key that your app uses to authenticate with the Google API Console.

getTING AN access token from Google

You just need to use the New OAuth2 provider command or the cs.NetKit.OAuth2Provider class with the name attribute equal to “Google” to get your token.

cs.NetKit.OAuth2Provider class with all the information given during the registration:

var $oAuth2 : cs.NetKit.OAuth2Provider
var $param : Object

$param:={name:"Google"; \
   permission:"signedIn"; \
   clientId:"499730024306-rfub401kvb2794llikrtb4fphigrggt7.apps.googleusercontent.com"; \
   clientSecret:"fc1kwxb6NMzEKi9Ka_fjvB2Z"; \
   redirectURI:"http://127.0.0.1:50993/authorize/"; \
   scope:"https://mail.google.com/"}
$oAuth2:=cs.NetKit.OAuth2Provider.new($param)
$token:=$oAuth2.getToken()

getTING AN access token from other servers

You can use the New OAuth2 provider command or the cs.NetKit.OAuth2Provider class with other OAuth 2.0 servers than Microsoft or Google. You just need to fill the authenticateURI and the tokenURI with the specific URIs of your OAuth 2.0 server and verify that the authorization code returned is in JSON format.

For example, you can connect your application to GitHub with the code below:

var $oAuth2 : cs.NetKit.OAuth2Provider
var $param : Object

$param:={permission:"signedIn"; \
clientId:"734e0b59xxx"; \
clientSecret:"125a576xxx"; \
redirectURI:"http://localhost:50993/authorize/"; \
scope:"repo, user"; \
authenticateURI:"https://github.com/login/oauth/authorize"; \
tokenURI:"https://github.com/login/oauth/access_token"}

$oAuth2:=cs.NetKit.OAuth2Provider.new($param)
$token:=$oAuth2.getToken()

Custom the result pages

To display your own page at the end of the authentication, you need to use authenticationPage and authenticationErrorPage attributes:

$param.authenticationPage:=Folder(fk web root folder).file("authentication.htm")
$param.authenticationErrorPage:=Folder(fk web root folder).file("error.htm")

We constantly strive to provide our users with the best possible experience, and we encourage you to share your thoughts and feedback on the 4D forum. Your feedback helps us better understand your needs and continuously improve our products and services.

Discuss

Tags 21, 4D NetKit, v20 R2

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy