Question

I want to connect with Google calender, Google contacts and Google+ in my grails application. I am able to connect only one google service at a time with available google provider. So I have to add new custom provider.

My code is

package org.scribe.api;
import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.*;


public class GoogleContactApi extends DefaultApi10a
{
private static final String AUTHORIZATION_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=%s";

@Override
public String getAccessTokenEndpoint()
{
    return "https://www.google.com/accounts/OAuthGetAccessToken";
}

@Override
public String getRequestTokenEndpoint()
{
    return "https://www.google.com/accounts/OAuthGetRequestToken";
}


@Override
public String getAuthorizationUrl(Token requestToken)
{
    return String.format(AUTHORIZATION_URL, requestToken.getToken());
}
}

my configuration

googleContact{
        api = org.scribe.builder.api.GoogleApi           

        key = '1xxxxxxxx'
        secret = 'xxxxxxxxxx'

        scope = 'https://www.google.com/m8/feeds'
        callback = "${grails.serverURL}/oauth/google/callback"
        successUri = "${grails.serverURL}/oauthCallBack/googleContact"
    }

But I am getting error Unknown provider googleContact, check your configuration..

Please provide guidance.

Was it helpful?

Solution

No need to create a custom provide to connect google with different google applications.

Just need to give different provider name in the code, e.g.,

Config.groovy

google {
    api = org.scribe.builder.api.GoogleApi
    key = 'XXX'
    secret = 'YYY'

    scope = 'https://www.googleapis.com/auth/userinfo.profile'

    callback = "${grails.serverURL}/oauth/google/callback"
    successUri = "${grails.serverURL}/oauthCallBack/google"
}

googlecontact {
    api = org.scribe.builder.api.GoogleApi
    key = 'XXX'
    secret = 'YYY'

    scope = 'https://www.googleapis.com/auth/calendar'              

    callback = "${grails.serverURL}/oauth/googlecontact/callback"
    successUri = "${grails.serverURL}/oauthCallBack/googlecontact"
}

View

<oauth:connect provider="googlecontact">Google Contact</oauth:connect>
<oauth:connect provider="google">Google</oauth:connect>

and OauthCallBackController

def google() {
    // your code
}

def googlecontact(){
    // your code
}

NOTE: use googlecontact if you use googleContact then you got error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top