|Manuals

Authenticating Users with OAuth 2.0 from Your Application

Your application can start an OAuth 2.0 authorization flow against an external identity provider — such as Google or Microsoft — from inside the application code. The end user completes the login in their browser, and your application receives the access token and the user’s profile information.

This is different from the OAuth 2.0 authentication method configured in the Server Manager: that one protects the access to the published application, while AuthenticateOAuth lets the application itself authenticate the user against a provider at any point.

The AuthenticateOAuth Method

Call the AuthenticateOAuth method of the VirtualUI object with the provider’s endpoints and your client credentials. The method returns a login URL.

Parameter Description
ClientId The client ID of your application, as registered with the provider.
ClientSecret The client secret of your application.
AuthorizationUrl The provider’s authorization endpoint.
AuthorizationParams Additional parameters for the authorization request, such as scopes.
TokenValidationUrl The provider’s token endpoint, where the authorization code is exchanged for an access token.
TokenValidationParams Additional parameters for the token request.
ProfileInformationUrl The provider’s user-info endpoint.
ProfileInformationParams Additional parameters for the user-info request.

Open the returned URL in the end user’s browser to start the flow — for example, with the OpenLinkDlg method. When the user completes the login, the browser shows a confirmation page and VirtualUI resolves the rest of the flow on the server side: it exchanges the authorization code for an access token and retrieves the user’s profile.

The OnAuthentication Event

When the flow finishes, the OnAuthentication event fires in your application:

procedure TForm1.VirtualUIAuthentication(Sender: TObject; const AuthMethod: string;
  Success: Boolean; const Data: string);
Parameter Description
AuthMethod The authentication method that completed. For this flow, oauth.
Success Whether the authentication succeeded.
Data A JSON document with the result.

On success, Data contains the clientId, the accessToken, and a userInfo object with the profile returned by the provider. On failure, it contains an errorMsg field instead.

Note: Code example pending — add Delphi, C#, and C++ samples once validated in the lab.

Read more