antony / grails-oauth-scribe

Grails Oauth plugin using the Scribe library
23 stars 40 forks source link

Can't import the Vendors APIs in grails 3 #56

Closed farkaskid closed 7 years ago

farkaskid commented 7 years ago

Hi, I've followed as you said in the docs but when i import the FacebookAPI in the application.groovy

import org.scribe.builder.api.FacebookApi

oauth {
    providers {
        facebook {
            api = FacebookApi
            key = 'my key'
            secret = 'my secret'
            successUri = "${application.baseUrl}/hello/oauthFb"
        callback = "${application.baseUrl}/oauth/facebook/callback"
    }
    }
}

I get this

$ grails compile --stacktrace --verbose                                              [11:01:32]
| Error Error occurred running Grails CLI: startup failed:
script1489642309788319590921.groovy: 1: unable to resolve class org.scribe.builder.api.FacebookApi
 @ line 1, column 1.
   import org.scribe.builder.api.FacebookApi
   ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1489642309788319590921.groovy: 1: unable to resolve class org.scribe.builder.api.FacebookApi
 @ line 1, column 1.
   import org.scribe.builder.api.FacebookApi
   ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:946)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:221)
    at groovy.lang.GroovyClassLoader$parseClass.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at groovy.util.ConfigSlurper.parse(ConfigSlurper.groovy:170)
    at org.grails.config.CodeGenConfig.loadGroovy(CodeGenConfig.groovy:148)
    at org.grails.cli.GrailsCli.loadApplicationConfig(GrailsCli.groovy:592)
    at org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:291)
    at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:269)
    at org.grails.cli.GrailsCli.main(GrailsCli.groovy:159)
| Error Error occurred running Grails CLI: startup failed:
script1489642309788319590921.groovy: 1: unable to resolve class org.scribe.builder.api.FacebookApi
 @ line 1, column 1.
   import org.scribe.builder.api.FacebookApi
   ^

1 error

here is the dependencies part of build.gradle

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.1.Final"
    compile "org.hibernate:hibernate-ehcache:5.1.1.Final"
    compile 'org.grails.plugins:spring-security-core:3.1.1'
    // compile 'org.scribe:scribe:+'
    // compile "org.grails.plugins:spring-security-oauth2:1.1.0"
    // compile "org.grails.plugins:spring-security-oauth2-facebook:1.0.0"
    compile 'org.grails.plugins:oauth:3.0.1'
    compile fileTree(dir: 'libs', include: '*.jar')
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    provided "org.codehaus.groovy:groovy-ant"
    runtime 'mysql:mysql-connector-java:5.1.29'
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.11.1"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

I've also tried with TwitterAPI, same issue. Also posted on Stack. I know it is class resolution error so I tried to include scribe classes manually with the scribe.jar but still nothing happens. Am i missing something obvious?. application.yml

oauth:
    providers:
        facebook:
            api: org.scribe.builder.api.FacebookApi
            key: 'my key'
            secret: 'my secret'
antony commented 7 years ago

Hi,

I've not personally tried this plugin with Grails 3, it was very kindly updated to Grails 3 by another user. However the error looks fairly understandable to me - and that is that the scribe library is missing.

I'm not sure how Grails 3 handles transient dependencies, but scribe is a dependency of the plugin and should therefore be included.

If you want to try manually including the correct scribe version in your build.gradle and trying again, that might help?

farkaskid commented 7 years ago

Thankyou for the reply. Now the thing is it is not an issue related to plugin but an grails specific issue. Here is what is found, this was in the list of changes while migrating from grails 3.1 to above.

application.groovy Changes An improvement was added to make groovy configuration behave like yml configuration when it comes to the CLI. Previously, configuration values in application.groovy were not available to commands like grails create-controller. A side effect of this change causes an exception when those commands are executed if the configuration relies on classes in the runtime.


Error occurred running Grails CLI: startup failed:
script14738267015581837265078.groovy: 13: unable to resolve class com.foo.Bar

The solution is to create a separate file called runtime.groovy in grails-app/conf. That file will not be parsed by the CLI and will only be included at runtime.

Now i realise that the same thing is happening to me. So i moved this segment to runtime.groovy

import org.scribe.builder.api.FacebookApi

oauth {
    providers {
        facebook {
            api = FacebookApi
            key = 'my key'
            secret = 'my secret'
            successUri = "${application.baseUrl}/hello/oauthFb"
        callback = "${application.baseUrl}/oauth/facebook/callback"
       }
    }
}

So there is no error and it compiles but as plugin docs mention to put this code segment in application.groovy, I think plugin does'nt work in this situation because when i use the

<oauth:connect provider="facebook" id="facebook-connect-link">Connect to Facebook</oauth:connect>

the link that renders have no redirectUrl

<a href="/oauth/facebook/authenticate?redirectUrl=" provider="facebook">Connect to Facebook</a>

so i get an exception again. What could be the reason for an empty RedirectUrl ?

exception

URI:/oauth/facebook/authenticate
Class:java.lang.IllegalArgumentException
Message:null
Caused by:Must provide a valid url as callback. Facebook does not support OOB
antony commented 7 years ago

This relates to another issue #57 and should be fixed by #58 . I'll review the full changelist from #58 as soon as I can and release a new version.

antony commented 7 years ago

I've released v4.0.0 which should solve the issue you are having.