How to integrate PowerServer 2022 R2 ?

Estimated reading: 4 minutes 53 views

Pre-Requisites

  • PowerBuilder 2022 R2
  • PowerServer 2022 R2
  • Visual-Guard Identity server 2020.3
  • .NET Core 6.0

Steps to Configure Visual Guard for PowerServer

Create and configure the PowerServer project as described in the PowerServer documentation.

  • Make sure “Use external auth service” and “I have read and agree to the license…” options are selected, as shown in the figure below.
  • Build and deploy the PowerServer project and make sure the application is deployed and PowerServer C# solution is generated successfully.

Go to the PowerServer C# solution > ServerAPIs project, add a reference to “Novalys.VisualGuard.Security.PowerServer.dll”. (You can get this DLL file from the Visual Guard Setup or the NuGet website).

In the PowerServer C# solution > UserExtensions project > UserStartup.cs file, modify the scripts as below (pay attention to the changes in the highlighted lines).

 public void ConfigureServices(IServiceCollection services)
 {
            // Configures the services of the PowerServer AppConfig module
            services.AddPowerServerAppConfig(this.Configuration, this.HostingEnvironment);

            // Configures the services of the PowerServer Authentication module 
            //services.AddPowerServerAuthentication(this.Configuration);

            //Adds Visual Guard Identity Server authentication/authorization to Power Server.
            services.AddVGPSIdentityServer(this.Configuration);

            // Configures the services of the PowerServer HealthCheck module 
            services.AddPowerServersHealthChecks(this.Configuration);

            // Configures the services of the PowerServer Logging module 
            services.AddPowerServerLogging();

            // Configures the services of the PowerServer OpenAPI module
            services.AddPowerServerOpenAPI();

            services.AddPowerServerDataProvider(this.GetType().Assembly);
  }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UsePowerServerPathBase();

            if (this.HostingEnvironment.IsDevelopment())
            {
                // Enables the exception page during development. It will list all exceptions for debugging
                app.UseDeveloperExceptionPage();

                // Configures the HTTP request pipeline for the PowerServer OpenAPI module
                app.UsePowerServerOpenAPI();
            }

            // Adds middleware for redirecting HTTP Requests to HTTPS.
            //app.UseHttpsRedirection();

            // Configures the HTTP request pipeline for the PowerServer Logging module
            app.UsePowerServerLogging();

            app.UseRouting();

            // Enables the compression of responses
            app.UseResponseCompression();

            //Adds Visual Guard Middleware            
            app.UseVGPSMiddleware();

            // Enables authentication
            app.UseAuthentication();

            // Enables authorization
            app.UseAuthorization();

            // Enables the welcome page
            app.UseWelcomePage("/");

            // Configures the HTTP request pipeline for the PowerServer HealthCheck module
            app.UsePowerServerHealthChecks();

            app.UseEndpoints(endpoints =>
            {
                // Adds the controller to the HTTP request pipeline
                endpoints.MapControllers();
            });
        }

Configure Visual Guard PowerServer configuration in the C# solution > UserExtensions project > AppConfig folder > AppConfig.json file. Here you can add all actions to be excluded, points to Visual Guard Identity Server, enables trace and much more.

{
  // Sets the environment type when starting PowerServer
  // The value can be overwritten by commandline argument, environment variable or other imported configuration under the identical name
  // see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration

  // For example, in the project folder, execute: dotnet run -- --POWERSERVER_ENVIRONMENTTYPE=Development
  // see https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-run#description

  // Or, in the output directory, execute: dotnet ServerAPIs.dll --POWERSERVER_ENVIRONMENTTYPE=Development
  // https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet#description
  "POWERSERVER_ENVIRONMENTTYPE": "Default",

  "ConnectionStrings": {
    // Saves the  connection string of the db that saves the configuration data. Will be referenced in AppConfigExtensions.AddPowerServerAppConfig 
    "AppConfig": "<appconfig connection string>"
  },
  "VGPSConfiguration": {
    "ExcludeActions": [
      "action1"
    ],
    "IdentityServerUrl": "https://identityserver.dev.visual-guard.com",
    "TraceLevel": "Verbose",
    "VGRACMode": "Silence",
    "PolicyName": "ServerAPIs",
    "PowerServerVersion": "V2022"
  }
}

Now in Visual Guard Console, add your Power Server application in the repository and create the desired permissions with Power Server security.

Click on Power Server Security and assign the CRUD operation accordingly to each data window or table and save it.

You can also map each PB component to new or added table. Right click on the VG application and click “Map PB Components”. Click on Save and Close.

In case new PB components are added to the application, you can refresh the same by right clicking on VG application and selecting “Reload all components for PB application”.

Assign the permission to role and to user or group accordingly.

Now, in PowerBuilder application login form, authenticate the user via Visual Guard Identity Server. Call the Visual Guard Identity Server and on success, sets the Bearer Token.

Now on each request to PowerServer, Visual Guard Token will be passed as Bearer as Authorization Request Header and will permit the user as per the rights assigned.