# Additional plugins.oauth.OAuthProviders

**URL:** <https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418>\
**Category:** Questions\
**Created:** [January 28, 2021, 3:23pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418 "2021-01-28T15:23:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [January 28, 2021, 3:23pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/1 "2021-01-28T15:23:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 10, 2021, 5:20pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/2 "2021-09-10T17:20:55Z")

</div>

Shame Christian didn’t get a reply on this.  
I too am now in the position of wanting to connect (nicely) to Sage Cloud (a UK accounts package) that uses OAuth and there isn’t a OAuthProvider for it.  
How can we go about creating requests for new OAuthProviders, or what can we put in place of that parameter in the “.build” to make something else work?  
Thanks  
Rafi

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 13, 2021, 6:52am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/3 "2021-09-13T06:52:40Z")

</div>

Hello,  
Starting with 2021.09 it is possible to build a custom api:

```auto
 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);
	}
}

```

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 13, 2021, 7:40am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/4 "2021-09-13T07:40:27Z")

</div>

> emera:  
> Hello,  
> Starting with 2021.09 it is possible to build a custom api:

Hi emera,  
thanks for replying and that looks like great news & a possible solution (in the future), however

1. I was hoping to be able to sort this now
2. I personally have not had a good ‘user experience’ with 2021.06 (on Mac), with various issues of it not responding until I click on a menu & general slowness [I should probably post something on forum about it ![;-)]( "Wink") ]  
It would be nice if the OAuth plugin was part of the package manager, then maybe we could have used it in an earlier version…  
Thanks

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 13, 2021, 7:57am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/5 "2021-09-13T07:57:51Z")

</div>

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.  
Please check the new release and in case you have other issues you can report them at [support.servoy.com](http://support.servoy.com).  
Best regards,  
Edit

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 13, 2021, 9:48am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/6 "2021-09-13T09:48:21Z")

</div>

Hi Edit,

> emera:  
> 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.

Thanks, I might test it, but it’s possible client might need solution sooner…

> 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.

I understand, thanks.

> Servoy Please check the new release and in case you have other issues you can report them at [support.servoy.com](http://support.servoy.com).  
> Best regards,  
> Edit

Will do.

Thanks

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 13, 2021, 9:53am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/7 "2021-09-13T09:53:27Z")

</div>

Or you can copy the oauth.jar from the rc (application\_server/plugins) to the older version.

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 13, 2021, 10:29am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/8 "2021-09-13T10:29:15Z")

</div>

> emera:  
> Or you can copy the oauth.jar from the rc (application\_server/plugins) to the older version.

That is exactly what I was going to try & do ![:D]( "Very Happy")

Thanks!

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 14, 2021, 12:04pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/9 "2021-09-14T12:04:34Z")

</div>

Hi Edit,  
Thanks (again) for your posts, I have now copied the OAuth plugin from the latest ‘rc’ to the current version of Servoy & it seems to work…  
After some playing around, I think I have now, almost, got it working.  
I had been using ‘Postman’ to do testing before moving to Servoy coding for call & I am now seeing an error that I get in Postman if I have the request ‘Client Authentication’ set as  
“Send as Basic Auth header”  
[attachment=0]Postman Header.png[/attachment]  
but when I have it set as  
“Send client credentials in body”  
[attachment=1]Postman Body.png[/attachment]  
it works!  
So, how can I make the plugin use the 2nd way??  
My code is

```auto
	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);

```

(I couldn’t seem to see anything in the plugin options…)

Thanks!

![Postman Header.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/4/4dfcf57dcc55862ec5faf3efe3164fa3ad725b87.png)

![Postman Body.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/2/222c8f797142783743b661762309dc5dee17c65f.png)

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 14, 2021, 1:17pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/10 "2021-09-14T13:17:09Z")

</div>

Hello,

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?

Or do you want to use the [client credentials grant type](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4)? That is not implemented by the plugin.

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 15, 2021, 10:31am UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/11 "2021-09-15T10:31:02Z")

</div>

Hi Edit,

> The client id and secret are already sent as body parameters, because the default http method to get the access token is POST.

Ok, but it still doesn’t seem to be working…

> 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 removed those, no change…

> 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)?

I am not specifying a ‘deeplink’ & have configured app with the deeplink\_svy\_oauth at the end (& this is how I got the Intuit QuickBooks OAuth to work)

> What error do you get when running your code?

```auto
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

```

The last line is from the callback method that is like your code above (I used the sample plugin code)…

> Or do you want to use the client credentials grant type? That is not implemented by the plugin.

I don’t.

As I mentioned, I got the equivalent error in Postman app when it was configured to send ‘Basic Auth Header’…

Thanks

Rafi

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 16, 2021, 1:42pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/12 "2021-09-16T13:42:20Z")

</div>

Indeed the error message means that Client authentication failed ( client is unknown, no client authentication included, or authentication method is unsupported).  
Possible reasons:  
No service with the provided clientServiceId was found, which is not the case since it worked in postman  
Authorization header was either of invalid format or not passed at all

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.

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 17, 2021, 12:05pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/13 "2021-09-17T12:05:22Z")

</div>

> emera:  
> 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.

Hi Edit,  
Success!!!  
That works!  
Thank you SO much!  
I can get on with writing the rest of the code now ![;-)]( "Wink")  
I hope you can update the plugin with the right bits now & get it out with 2021.09 release (& that it will still work in earlier releases…)  
All the best  
Rafi

---

<div class="post-metadata">

**Author:** ![emera](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@emera](https://forum.servoy.com/u/emera)\
**Post date:** [September 17, 2021, 12:30pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/14 "2021-09-17T12:30:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [September 17, 2021, 12:36pm UTC](https://forum.servoy.com/t/additional-plugins-oauth-oauthproviders/20418/15 "2021-09-17T12:36:59Z")

</div>

> emera:  
> 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.

Thanks ![;-)]( "Wink")  
Great!
