Always getting "redirect_uri_mismatch" after authentication

191 views
Skip to first unread message

mage_stat

unread,
Feb 5, 2013, 4:48:34 AM2/5/13
to oauth...@googlegroups.com
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.

API Access Re

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);
            // Here the Google Exception is thrown.
            $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'));
    }

The controller reads out the code and then try to authenticate the client. The client sends the authentication request and getting so the response:

object(Google_HttpRequest)#21 (10) { ["batchHeaders":"Google_HttpRequest":private]=> array(4) { ["Content-Type"]=> string(16) "application/http" ["Content-Transfer-Encoding"]=> string(6) "binary" ["MIME-Version"]=> string(3) "1.0" ["Content-Length"]=> string(0) "" } ["url":protected]=> string(42) "https://accounts.google.com/o/oauth2/token" ["requestMethod":protected]=> string(4) "POST" ["requestHeaders":protected]=> array(2) { ["content-type"]=> string(33) "application/x-www-form-urlencoded" ["content-length"]=> int(326) } ["postBody":protected]=> string(326) "code=4%2FENmQxxnPbz3tGCv2vffe5nil5BJd.gqzFk8K5uFgaOl05ti8ZT3a39TlTeQI&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fsub.domain.com%2Ffolder%2Fstatistic%2Fgoogle%2Foauth2callback%2F&client_id=264060109523-8ibgm8lm9c0cdlhatauhbr9jcohj19t7.apps.googleusercontent.com&client_secret=secret-deleted" ["userAgent":protected]=> string(46) "Aromicon Statistic google-api-php-client/0.6.0" ["responseHttpCode":protected]=> int(400) ["responseHeaders":protected]=> array(10) { ["cache-control"]=> string(46) "no-cache, no-store, max-age=0, must-revalidate" ["pragma"]=> string(8) "no-cache" ["expires"]=> string(29) "Fri, 01 Jan 1990 00:00:00 GMT" ["date"]=> string(29) "Tue, 05 Feb 2013 09:06:23 GMT" ["content-type"]=> string(16) "application/json" ["x-content-type-options"]=> string(7) "nosniff" ["x-frame-options"]=> string(10) "SAMEORIGIN" ["x-xss-protection"]=> string(13) "1; mode=block" ["server"]=> string(3) "GSE" ["transfer-encoding"]=> string(7) "chunked" } ["responseBody":protected]=> string(39) "{ "error" : "redirect_uri_mismatch" }" ["accessKey"]=> NULL }

I my opinion the URIs ar correct and i can't see any error. Where is the error?


Reply all
Reply to author
Forward
0 new messages