Question

I'm using the scribe library to do my OAuth login and requests. I am only using one API provider and wondered if it's possible to autowire my OAuthService rather than having to .getService() every time?

I've read blogs on how to autowire the OAuthServiceProvider and then .getService() (here and here) but nothing on the Service itself. It's created in the class using a builder:

    public OAuthService getOAuthService() {
        return new ServiceBuilder().provider(MyApi.class)
            .apiKey(myConsumerKey).apiSecret(mySecretKey())
            .build();
    }

Ideally I want something like this in my servlet-context.xml:

    <bean id="myService" class="org.scribe.model.OAuthService">
        <!-- constructor service somehow -->
    <bean>

Note that I'm not using a Service Provider that is already included in the library

Was it helpful?

Solution

I managed to achieve this with:

<beans:bean id="myApiConfig" class="org.scribe.model.OAuthConfig">
    <beans:constructor-arg value="${key.access}"/>
    <beans:constructor-arg value="${key.secret}"/>
    <beans:constructor-arg value="${url.callback}"/>
    <beans:constructor-arg type="org.scribe.model.SignatureType" value="QueryString"/>
    <beans:constructor-arg value="some-permission"/>
    <beans:constructor-arg><beans:null /></beans:constructor-arg>
</beans:bean>

<beans:bean id="myApi" class="com.chartminder.app.MyApi">
</beans:bean>

<beans:bean class="org.scribe.oauth.OAuth10aServiceImpl">
    <beans:constructor-arg ref="myApiConfig"/>
    <beans:constructor-arg ref="myApi"/>
</beans:bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top