Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Create OAuth2 Application from JAVA code in portlet
I am using Eclipse IDE with Liferay version 7.1.3.
I need to be able to create a OAuth 2 Application via code rather than doing it manually from Control Panel/Configuration/OAuth 2 Administration.
This is just a POC, so the Java code will initially be in a background Portlet MVCPortlet Class.
I have this as an external depenance - com.liferay.oauth2.provider.service-1.0.2-sources.jar
I have this in my module build.gradle - compileOnly group: "com.liferay", name: "com.liferay.oauth2.provider.service"
I have been looking at using OAuth2ApplicationServiceImpl.addOAuth2Application(...) But I am not familiar enough with JAVA to get this working. I assume it needs an import into the portlet.java file.
If anyone has any ideas, I'd be grateful to hear them.
Thanks...in advance.
Hi Robert.
Looks like you added a dependency on the OAuth 2 service implementation JAR and not its API.
The one you want is: com.liferay.oauth2.provider.api
A good example for how to use this API can be found here:
https://github.com/liferay/liferay-portal/blob/a165740c8b1bdbf95c8f89b39cf6738e73b57d0b/modules/apps/oauth2-provider/oauth2-provider-shortcut/src/main/java/com/liferay/oauth2/provider/shortcut/internal/instance/lifecycle/FragmentRendererPortalInstanceLifecycleListener.java#L65-L86
The scopes assignment is probably the most tricky part, but hopefully with that example you can get it something working.
Let me know how you get on :)
-Stian