Hi all,
Is there a way to use the oAuth plugin in Servoy when the service I want to connect to is not listed in plugins.oauth.OAuthProviders?
Or do I have to track the oauth tokens manually using the http plugin?
var customApi = plugins.oauth.customApi("https://example.com/oauth2/default/v1/authorize", //authorization base url
"https://example.com/oauth2/default/v1/token") //access token endpoint
.withAccessTokenExtractor(plugins.oauth.OAuthTokenExtractors.OpenIdJson); // other possible extractors: plugins.oauth.OAuthTokenExtractors.OAuth2
// or plugins.oauth.OAuthTokenExtractors.OAuthJson
var builder = plugins.oauth.serviceBuilder(clientid) //client/application ID
.clientSecret(secret) //client secret
.deeplink("deeplink")
.callback(callback, 30)
//.responseType("id_token")
.state('mystate-1235')
.scope("openid email");
service = builder.build(customApi);
application.output('help redirect url: '+plugins.oauth.getUsedRedirectUrl(builder));
}
catch (exception)
{
application.output(exception);
}
}
/**
* TODO generated, please specify type and doc for the params
* @param result
* @param auth_outcome
*
* @properties={typeid:24,uuid:"35B3D11B-8A1F-4CAB-9EB1-CD334B14A1B0"}
*/
function callback(result, auth_outcome) {
if (result)
{
service = auth_outcome;
application.output("success: access token "+service.getAccessToken());
application.output("id token: "+service.getIdToken());
forms.main.controller.show();
}
else
{
plugins.dialogs.showInfoDialog("error",auth_outcome);
}
}
emera wrote:Hello,
Starting with 2021.09 it is possible to build a custom api:
emera wrote:Servoy 2021.09 rc is released, so it is possible to test it now. The final version will be released at the end of the month.
The OAuth plugin is a java plugin and is shipped with Servoy and it is not part of the web package manager, which contains only angular packages.
Servoy Please check the new release and in case you have other issues you can report them at support.servoy.com.
Best regards,
Edit
emera wrote:Or you can copy the oauth.jar from the rc (application_server/plugins) to the older version.
var customApi = plugins.oauth.customApi("https://www.sageone.com/oauth2/auth/central",
"https://oauth.accounting.sage.com/token")
.withAccessTokenExtractor(plugins.oauth.OAuthTokenExtractors.OAuthJson);
var builder = plugins.oauth.serviceBuilder(sage_auth_clientId)
.additionalParameters({'filter': 'apiv3.1', 'grant_type': 'authorization_code'})
.clientSecret(sage_auth_clientSecret)
.responseType("code")
.scope(sage_auth_scope)
.state(sage_auth_state)
.callback(scopes.auth.deeplinkSage, 30)
.build(customApi);
The client id and secret are already sent as body parameters, because the default http method to get the access token is POST.
The client id and secret are already sent as body parameters, because the default http method to get the access token is POST.
'grant_type': 'authorization_code' is not needed as an additional parameter, it is added automatically.
.responseType("code") is also the default
I see that the deeplink method name is missing, then the last part of your redirect url is "deeplink_svy_oauth" (please check the docs of builder.deeplink())
Did you configure in your app the redirect url to end with deeplink_svy_oauth (where you also have the client id and secret)?
What error do you get when running your code?
ERROR plugin.oauth - Could not set the oauth code {"error":"invalid_client","error_description":"Parameter 'client_id' and/or 'client_secret' are invalid."} com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse: {"error":"invalid_client","error_description":"Parameter 'client_id' and/or 'client_secret' are invalid."}
at com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.generateError(OAuth2AccessTokenJsonExtractor.java:75) ~[scribejava-core.jar:?]
at com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:46) ~[scribejava-core.jar:?]
at com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor.extract(OAuth2AccessTokenJsonExtractor.java:16) ~[scribejava-core.jar:?]
at com.github.scribejava.core.oauth.OAuth20Service.sendAccessTokenRequestSync(OAuth20Service.java:39) ~[scribejava-core.jar:?]
at com.github.scribejava.core.oauth.OAuth20Service.getAccessToken(OAuth20Service.java:73) ~[scribejava-core.jar:?]
at com.github.scribejava.core.oauth.OAuth20Service.getAccessToken(OAuth20Service.java:68) ~[scribejava-core.jar:?]
at com.servoy.extensions.plugins.oauth.OAuthService.setAccessToken(OAuthService.java:112) ~[oauth.jar:?]
at com.servoy.extensions.plugins.oauth.OAuthServiceBuilder.lambda$buildWithCallback$0(OAuthServiceBuilder.java:351) [oauth.jar:?]
at com.servoy.extensions.plugins.oauth.OAuthServiceBuilder$$Lambda$1093/0x000000001fee1990.run(Unknown Source) [oauth.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
at java.lang.Thread.run(Unknown Source) [?:?]
ERROR Could not set the oauth code
Or do you want to use the client credentials grant type? That is not implemented by the plugin.
emera wrote:I added a new method to the custom api builder:
plugins.oauth.customApi("https:......", "https://....").withClientAuthentication(plugins.oauth.ClientAuthentication.Request_Body_AuthenticationScheme)
I sent you a jar for testing as a private message (i built it locally and it doesn't have docs so maybe it's not a good idea to attach it here)
Please let me know if you've got it and if it works for you.
emera wrote:You're welcome! I'm happy it works for you.
Servoy 2021.09 final will contain the fix.
The jar is going to be pretty much the same, but it will also have docs.
Users browsing this forum: Google [Bot] and 3 guests