How can we call an OAuth Service Helper End Point using Freedom UI (OAuth Authentication Service)

I have gone through the academy documentation I am unable to find anything that tells me how I can consume an OAuth service like we can used in Classic UI.

 

The sample code used in Classic UI.

Terrasoft.ServiceOAuthAuthenticatorEndpointHelper.getAuthorizationGrantUrl(
		this.get("UsrOAuthApplicationId").value,
		function(success, url) {
			if (success) {
				if (url) {
					window.open(url);
				}
			} else {
				this.showInformationDialog("Login Failed");
			}
			Ext.callback(callback, scope);
		}, this);
}

 

Can anybody tell how can I use the same functionality in Freedom UI?

 

Thanks in advance.

 

Like 0

Like

6 comments

Not sure if there's a Freedom UI specific way in the sdk (but I've not seen anything that looks like it yet). However, you should still be able to call Terrasoft.ServiceOAuthAuthenticatorEndpointHelper.getAuthorizationGrantUrl from a Freedom UI page for now. 

Ryan Farley,

 

I have tried this code but it's not working in Freedom UI. Can you please guide me some way around to call OAuth Web Service in Freedom UI Page.

 

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "usr.OAuthLoginButton",
		/* Implement the custom query handler. */
		handler: async (request, next) => {
			var oAuthAppId = await request.$context.LookupAttribute_u6rb81v;
			Terrasoft.ServiceOAuthAuthenticatorEndpointHelper.getAuthorizationGrantUrl(
				oAuthAppId.value,
				function(success, url) {
					console.log(url);
					if (success) {
						if (url) {
							window.open(url);
						}
					} else {
						this.showInformationDialog("Login Failed");
					}
					Ext.callback(callback, scope);
				}, this);
			return next?.handle(request);
		}
	}
]

 

Ryan Farley,

 

Can you please guide us on this?

Hello,

You can try calling your OAuth web service using an HTTPClient, here is an example of how to use it:

{
                request: "crt.HandleViewModelInitRequest",
                handler: async (request, next) => {
                    const httpClientService = new sdk.HttpClientService();
                    const endpoint =
                        "http://data.fixer.io/api/latest?access_key=578b5bcad95455a0a0fddddf83f1f269&symbols=USD";
                    const response = await httpClientService.get(endpoint);
                    request.$context.EurToUsd = 'EUR/USD: ' + response.body.rates.USD;
                    return next?.handle(request);
                },
            },

 

Dmytro Vovchenko,

 

We can't use this approach because the client secret is encrypted. If you tried to get the secret key from the table. We are restricted to use the build in OAuth Service in Freedom UI as it was working with Classic UI.

Syed Ali Hassan Shah,

I consulted the developers and it looks like currently there is no other way to call the OAuth service. Not all services from 

Terrasoft class transferred to a new UI and ServiceOAuthAuthenticatorEndpointHelper is one of them.

Show all comments