Re: [oauth2-dev] redirect_uri_mismatch for oauth2 analytics api

1,086 views
Skip to first unread message

Breno de Medeiros

unread,
Feb 5, 2013, 10:08:59 AM2/5/13
to oauth...@googlegroups.com

The redirect_uri you should provide is the one you registered in the APIs console and where you expect to receive the Auth token.

On Feb 5, 2013 1:11 AM, "mage_stat" <wsh...@gmail.com> wrote:
Hello,

im trying to getting access to Google Analytics Report API, but i'm always getting the "redirect_uri_mismatch" error after clicking the "grant access" button.
Im using the latest PHP Client as follows:

            $this->_gac = new Google_Client();
            $this->_gac->setApplicationName('Secret Application');
            $this->_gac->setClientId('client id removed');
            $this->_gac->setClientSecret('Secret Key');
            $this->_gac->setRedirectUri(Mage::getUrl('statistic/google/oauth2callback')); // this generates the uri like http://some.subdomain.com/folder/index.php/statistic/google/oauth2callback
            $this->_gac->setDeveloperKey('developer key');
            $this->_gac->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
            $this->_gac->setUseObjects(true);
            $this->_gac->setAccessType('offline');

After this i generate the Link with 
$this->getClient()->createAuthUrl();

After clicking the link, i will be redirected to google and asked for access. After clicking the button, i will be redirect to my redirect uri the controller will be triggered:

    public function oauth2callbackAction()
    {
        $code = $this->getRequest()->getParam('code');
        $client = Mage::helper('aromicon_statistic/google_analytics_data')->getClient();

        if(isset($code)){
            $client->authenticate($code);
            $offlineToken = $client->getAccessToken();
$refreshToken = $client->getRefreshToken();
            Mage::getConfig()->saveConfig( Aromicon_Statistic_Helper_Data::XML_PATH_CONFIG_GOOGLEANALYTICS_ACCESS_TOKEN ,$offlineToken);
    Mage::getConfig()->saveConfig( Aromicon_Statistic_Helper_Data::XML_PATH_CONFIG_GOOGLEANALYTICS_REFRESH_TOKEN ,$refreshToken);
        }
        $this->_redirect('adminhtml/system_config/edit', array('section'=>'aromicon_statistic'));
    }


--
You received this message because you are subscribed to the Google Groups "Developer Forum for Google API Access using OAuth2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oauth2-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

mage_stat

unread,
Feb 6, 2013, 2:02:07 AM2/6/13
to oauth...@googlegroups.com
Sorry about this post, it wasn't complete. I have opened a second one. Just answering your question. 
The redirect url is registered in API Console. The url_redirect_mismatch error appears after getting the code and trying to authorize the client to get the access and refresh token. The error is thrown after i call $client->authenticate($code); and is the response on the curl request.

Thanks for help.

Breno de Medeiros

unread,
Feb 6, 2013, 12:13:28 PM2/6/13
to oauth...@googlegroups.com
If you're using the same redirect_uri in the call
$client->authenticate($code), then possibly it's an encoding issue.
That call should be a url-encoded POST request.
> --
> You received this message because you are subscribed to the Google Groups
> "Developer Forum for Google API Access using OAuth2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to oauth2-dev+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
--Breno

mage_stat

unread,
Feb 6, 2013, 2:24:12 PM2/6/13
to oauth...@googlegroups.com
Sorry for waisting your time. I have found the error.   

 I have redirect, catched and logged the post to my controller: 

    [code] => 4/A9Gr5SuO9DbgnPwaaUJv8Pn-h5Lw.guWyaCguipAbOl05ti8ZT3ZPubpheQI
    [grant_type] => authorization_code
    [client_secret] => ***its_a_secret***

In this redirect URL there isn't the index.php. I have insert both urls in the API Console, but it doesn't work. 
In my opion the $this->_gac->setRedirectUri(Mage::getUrl('statistic/google/oauth2callback')); sets the URL to
http://sub.domain.com/whisky/index.php/statistic/google/oauth2callback/, but the authentication POST Request sends it without index.php.

Finally i've changed the request_uri at the Google_Oauth2 authenticate action hardcoded to http://sub.domain.com/whisky/index.php/statistic/google/oauth2callback/ and I get the access token. 

Thanks for help.
Reply all
Reply to author
Forward
0 new messages