Before making changes to the PowerBuilder client app, let's follow the steps below to make sure 1) the PowerBuilder application can run successfully, 2) the app has been deployed as an installable cloud app successfully, and 3) the PowerServer C# solution (including the built-in OAuth server) has been successfully generated.
In this tutorial, we will take Sales Demo as an example.
Step 1: Select Windows Start | Appeon PowerBuilder 2022, and then right-click Example Sales App and select More | Run as administrator.
Step 2: When the SalesDemo workspace is loaded in the PowerBuilder IDE, click the Run button in the PowerBuilder toolbar.
Step 3: When the application main window is opened, click the Address icon in the application ribbon bar and make sure data can be successfully retrieved.
Step 4: Create and configure a PowerServer project for the Sales Demo app (detailed instructions are provided in Quick Start > Guide 1).
IMPORTANT: In the .NET Server page > Advanced tab, select Use built-in OAuth server from the Auth Template list box.
Step 5: Deploy the application as an installable cloud app. The PowerServer C# solution is generated, but the installable cloud app cannot run yet because further settings and changes are required, as explained in the subsequent sections.
The PowerServer C# solution contains a built-in OAuth server and the authentication class files as shown below.
-
The built-in OAuth server uses the IdentityServer4 framework. It is included in the ServerAPIs project; it will run automatically when the PowerServer Web APIs (the ServerAPIs project) runs. You can use another OAuth server (such as Google OAuth 2.0 Authorization Server) instead of using the built-in server. In this tutorial, we will use the built-in server to authenticate the user credentials and return the token.
-
DefaultConfig.cs defines two OAuth authorization flows: client credentials and resource owner password; and in each flow defines client ID, client name, grant type, client secret, scope etc. If you want to define different credentials, you can change this file accordingly.
-
DefaultUserStore.cs defines two users by default. You can change this file to define more users.
The users can also be defined and stored in the database or LDAP server. Refer to Validate username and password against a database or Validate username and password against an LDAP server for more information.
-
DatabaseUserStore.cs can be added with scripts to connect with an authentication database where the users are defined and stored.
-
-
The authentication class and configuration files will be used by the PowerServer Web APIs to validate the token (passed from the client) against the OAuth server and, if validation is successful, data will be obtained from the database.
-
Authentication.json contains the settings for enabling the authentication feature ("PowerServer:EnableAuthentication") and specifying the URL of the OAuth server ("Authority").
The "PowerServer:EnableAuthentication" setting is set to true by default. Setting it to false will turn off the authentication feature. The "Authority" setting is set to the OAuth server URL which is the same as the Web API URL by default, as the built-in OAuth server resides in the PowerServer Web API. If you set up your own OAuth server, change the URL in this file accordingly.
-