Cant inject OAuthTokenIssuer to controller

Hi,
I am triyng to do social login as the example on github, but when I try to use OAuthTokenIssuer i get the excetion:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.haulmont.restapi.auth.OAuthTokenIssuer' available

Im on web. trying to inject to controller.
Thanks

Hi,

OAuthTokenIssuer can be injected only into controllers of REST-API Spring Context.

@artamonov this is what I’m doing, it is inside @RestCentoller
Thanks

Please ensure that it is defined in package scanned by REST-API Spring context. Annotation does not matter.

Can you please show me in this project: GitHub - cuba-platform/sample-social-login: Custom authentication for CUBA Applications using Facebook where is that definition? because your are using it there.
Thanks

Check rest-dispatcher-spring.xml file:

<context:component-scan base-package="com.company.demo.restapi"/>

REST-API creates controllers defined in com.company.demo.restapi, not web dispatcher servlet.

You can read more about custom controllers in REST-API context here: Creating Custom OAuth2 Protected Controllers - CUBA Platform. Developer’s Manual

@artamonov Sure I do have that. and all the other cuba dependencies are working in this controller.
Maybe there is another way to generate the token?
Going nuts )-:
Thanks.

If you still cannot wire the dependency, you can reproduce the problem and attach your demo here. We will be able to help you then

One more thing to know: Web Spring context does not scan package with REST-API controllers.

See web-spring.xml:

<!-- Annotation-based beans -->
<context:component-scan base-package="com.company.demo">
    <context:exclude-filter type="regex" expression="com\.company\.demo\.restapi\..*"/>
</context:component-scan>

So, only REST-API context scans com.company.demo.restapi package.

This one did the trick. Can you please explain why?
Is it because both of the contexts was scanning the rest?
Thanks for your help.
Avi

Web application consist of one main Spring context and additional REST-API Spring context. Each context scans packages mentioned in component-scan of the corresponding -spring.xml config file and creates beans.

When you define @Component in the package scanned by both main and REST contexts - there will be two instances of bean: one in main context and one in REST. The instance defined in the main context will not be able to find beans from REST-API context and you will see the error.