hwi / HWIOAuthBundle

OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.
MIT License
2.27k stars 797 forks source link

Argument 1 passed to OAuthUtils::getLoginUrl() must be an instance of Request, null given #975

Closed madmis closed 8 years ago

madmis commented 8 years ago

Sometimes when i reload page, i get this error

Type error: Argument 1 passed to HWI\Bundle\OAuthBundle\Security\OAuthUtils::getLoginUrl() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72

http://prnt.sc/afyzo7

This is info from logs:

[2016-03-16 15:42:24] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Argument 1 passed to HWI\Bundle\OAuthBundle\Security\OAuthUtils::getLoginUrl() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72" at /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Security/OAuthUtils.php line 146 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to HWI\\Bundle\\OAuthBundle\\Security\\OAuthUtils::getLoginUrl() must be an instance of Symfony\\Component\\HttpFoundation\\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72 at /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Security/OAuthUtils.php:146)"} []

Code to render login links on the main page (copied from bundle)

            <div>
                {% block hwi_oauth_content %}
                    {% if error is defined and error %}
                        <span>{{ error }}</span>
                    {% endif %}
                    {% for owner in hwi_oauth_resource_owners() %}
                        <a href="{{ hwi_oauth_login_url(owner) }}">
                            {{ owner | trans({}, 'HWIOAuthBundle') }}
                        </a> <br />
                    {% endfor %}
                {% endblock hwi_oauth_content %}
            </div>

Do you know the cause of this error?

http://prnt.sc/afz4jv - additional info (symfony 3.0.3, php 7.0.4-6).

madmis commented 8 years ago

I can reproduce this error only for authenticated users.

evrardcnam commented 8 years ago

It's produce same error for me.

arodiss commented 8 years ago

I dig this issue a bit and here is the outcome For me (Symfony 3.0.4) issue happens only on first load, i.e. when no cache is available. Every subsequent request goes fine, unless I remove cache manually.

The problem is that RequestCompilerPass injects call setRequest() in hwi_oauth.templating.helper.oauth, passing @request or @request_stack as argument For some reason, on first load RequestStack::getMasterRequest() (called in OAuthHelper::setRequest()) returns null, and so null is stored in OAuthHelper::$request, and then null is passed further to OAuthUtil, which triggers this issue.

Looks like problem is related to the services initialization order.

arodiss commented 8 years ago

Calls order on first load:

Spawnrad commented 8 years ago

I have the same error. Someone have solved this issue? Symfony 3.0.6

blackknight467 commented 8 years ago

I've run into the same issue.

qRoC commented 8 years ago

+1 same too

Zeyckler commented 8 years ago

Same error here with php 5.6 and SF 2.8