Register a client/app with oAuth2 module

Hi manny, can you provide the steps to register a client/app with the Oauth2 module using the online form? I’ve looked the page on Client Developers and seen the two available videos, but none shows using the online form. When using the online form, the registration process seem to fail to persist all the necessary data in the oauth2 DB tables. Below are the steps I go:

  1. install OpenMRS Standalone 1.11.x
  2. login as admin and add the oauth2 and then the fhir module
  3. create a new user (must have admin privileges in order to see the Admin page hence register a new app/client for oauth2)
  4. login as the new user
  5. Click on Manage Registered Application under Oauth2 Module on Admin page
  6. Click on Register New Application, fill out the form and click the Register Application – this take me to a blank page (http://localhost:8081/openmrs-standalone/module/oauth2/client/registered/view/4.form). Here’s the exception (beware: I have enhanced error messages):

SEVERE: Servlet.service() for servlet openmrs threw exception java.lang.IllegalStateException: encodeCredentials(): Invalid credentials for OAuth2 Client (NULL clientIdentifier or of ZERO length): foo2. Request generation of new credentials at org.openmrs.module.oauth2.api.impl.ClientRegistrationServiceImpl.encodeCredentials(ClientRegistrationServiceImpl.java:125) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198) at com.sun.proxy.$Proxy263.encodeCredentials(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy264.encodeCredentials(Unknown Source) at org.openmrs.module.oauth2.web.controller.ViewEditRegisteredClientFormController.showForm(ViewEditRegisteredClientFormController.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

The exception message above says: “Request generation of new credentials”… again I don’t see a way of doing this from the admin page.

  1. Go back to the admin page and then back to the registered apps, you would see the app that was just registered, but then again clicking on it, results in a blank page.
  2. Looking at the DB tables, I see missing client ID, credentials etc.

I also see warning in the log such as: WARN - DefaultHandlerExceptionResolver.handleHttpRequestMethodNotSupported(194) |2016-04-29 03:06:05,512| Request method ‘GET’ not supported

Am I missing something in the above steps? I appreciate your help with this!

Environment: Platform 1.11.1 (Standalone), oauth2-openmrs-1.11.x

Reference:

Has anyone successfully registered an outh2 client using the online registration form provided by the oauth2 module? If yes, please let me know the steps. I’ve looked the page on Client Developers and seen the two available videos, but none shows using the online form. When using the online form, the registration process seem to fail to generate hence persist all the necessary data in the oauth2 DB tables.

Below are the steps I do:

  1. install Platform 1.11.x Standalone Edition
  2. login as admin and add the oauth2 and then the fhir module
  3. create a new user (must have admin privileges in order to see the Admin page hence register a new app/client for oauth2)
  4. login as the new user
  5. Click on Manage Registered Application under Oauth2 Module on Admin page
  6. Click on Register New Application, fill out the form and click the Register Application – this takes me to a blank page (http://localhost:8081/openmrs-standalone/module/oauth2/client/registered/view/4.form). Here’s the exception (beware: I have enhanced some of the error messages):

SEVERE: Servlet.service() for servlet openmrs threw exception
java.lang.IllegalStateException: encodeCredentials(): Invalid credentials for OAuth2 Client (NULL clientIdentifier or of ZERO length): foo2. Request generation of new credentials
	at org.openmrs.module.oauth2.api.impl.ClientRegistrationServiceImpl.encodeCredentials(ClientRegistrationServiceImpl.java:125)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
	at com.sun.proxy.$Proxy263.encodeCredentials(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:121)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at com.sun.proxy.$Proxy264.encodeCredentials(Unknown Source)
	at org.openmrs.module.oauth2.web.controller.ViewEditRegisteredClientFormController.showForm(ViewEditRegisteredClientFormController.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

The exception message above says: “Request generation of new credentials”… again I don’t see a way of doing this from the admin page.

  1. Then, go back to the admin page and then back to the registered apps page, I would see the app that was just registered, but then again clicking on it, results in a blank page.
  2. Looking at the DB tables, I see missing client ID, credentials etc. I think the primary problem is that the oauth2 module fails to determine the identity of the logged in user.

Am I missing something in the above steps? If the registration form doesn’t work, is there a script to manually create/register clients?

Additionally. I see warning in the log such as:

WARN - DefaultHandlerExceptionResolver.handleHttpRequestMethodNotSupported(194) |2016-04-29 03:06:05,512| Request method 'GET' not supported

It’s also not clear where the ROLE.CLIENT etc are configured for oauth2 and how (if at all) mapped onto OpenMRS roles. Thanks in advance for your help!