yiisoft / yii2-authclient

Yii 2 authclient extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
464 stars 246 forks source link

Google oauth2: scopes #206

Closed zlakomanoff closed 5 years ago

zlakomanoff commented 6 years ago

What steps will reproduce the problem?

config: 'scope' => 'profile email https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.login'

What's expected?

authorization success

What do you get instead?

Request failed with code: 400, message: { "error": "redirect_uri_mismatch", "error_description": "Bad Request" }

Additional info

Q A
Yii version 2.0.15
Yii Auth Client version 2.1.6
Yii HTTP Client version 2.0.7
PHP version 7.2.3
Operating system Arch Linux
zlakomanoff commented 6 years ago

looks like auth urls is stuck (https://developers.google.com/identity/protocols/OAuth2WebServer) and need update OAuth2.php defaultReturnUrl method just add

unset($params['authuser']);
unset($params['session_state']);
unset($params['prompt']);

to unset block

easy money :)

lukos commented 6 years ago

Isn't this error saying that you have a different redirect uri in the Google Developer Account than you are using locally to callback? The redirect uri you set in the Google account has to match the one used in this plugin e.g. for google: http://yourhost.name/site/auth?authclient=google site/auth should match what you used for the auth handler (in this example SiteController::auth())

yii-bot commented 6 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

Felli commented 6 years ago

Shouldn't need to use the https://www.googleapis.com/auth/plus.login scope unless you're wanting to use it for access of social features.

https://www.googleapis.com/auth/plus.me scope is not recommended as a login scope because, for users who have not upgraded to Google+, it does not return the user's name or email address.

newscloud commented 5 years ago

Please advise. I'm running into this on my live site at https://MeetingPlanner.io :( and my localhost test site. I didn't realize it broke when I updated to OAuth2. Facebook login works but not google.

My site urls match with google in the console. image

Try it here https://meetingplanner.io/site/signup

image

Exception – yii\authclient\InvalidResponseException Request failed with code: 400, message: { "error": "redirect_uri_mismatch", "error_description": "Bad Request" }

yuracher commented 5 years ago

The same as @newscloud, in all my past projects, I've noticed it yesterday.

samdark commented 5 years ago

New version was just tagged. Please update.

newscloud commented 5 years ago

This fixed it for me. Thanks @samdark "require": { "yiisoft/yii2": "*", "yiisoft/yii2-authclient": "~2.1.7",

cmsdevels commented 5 years ago

Request failed with code: 400, message: { "error": "redirect_uri_mismatch", "error_description": "Bad Request" }

Та же проблема появилась сегодня на всех проектах

lukos commented 5 years ago

This is not an error with the plugin but says that the registered redirect uri doesn't match what you are passing.

Do you think this is broken or have you changed your redirect uri and caused this error?

lukos commented 5 years ago

Это не ошибка с плагином, но говорит, что зарегистрированный URI перенаправления не соответствует тому, что вы передаете.

Вы думаете, что это не работает или вы изменили URI перенаправления и вызвали эту ошибку?

cmsdevels commented 5 years ago

URI правильный, пробовал пересоздать проект думал проблема в лимитах, но нет. Также сделал все обновления которые описаны выше. Проблема только в Google, все остальные работают отлично. У товарища который писал выше комментарий также не проходит авторизация https://meetingplanner.io/site/signup

lukos commented 5 years ago

When did it stop working? Did you update the yii2-authclient plugin and then it failed? Is this a brand-new application with the latest plugin version? Did you modify the redirect uri at Google?

Когда это перестало работать? Вы обновили плагин yii2-authclient, а затем произошел сбой? Это совершенно новое приложение с последней версией плагина? Вы изменили URI перенаправления в Google?

cmsdevels commented 5 years ago

перестало работать сегодня, без обновления, URI не менял

после появления проблемы сменил yiisoft/yii2-authclient (2.1.7 => 2.1.8) также обновил yiisoft/yii2 (2.0.20 => 2.0.21) не помогло

lukos commented 5 years ago

Maybe check that the redirect uri is still set in the Google console. Maybe they have "fixed" something and the comparison is more strict than before. Maybe they have broken something but it will take some time to find out. I do not use Google auth on Yii so I can't check whether my system is working.

Может быть, проверьте, что URI перенаправления все еще установлен в консоли Google. Может быть, они что-то «исправили» и сравнение более строгое, чем раньше. Может быть, они что-то сломали, но это займет некоторое время, чтобы узнать. Я не использую аутентификацию Google на Yii, поэтому не могу проверить, работает ли моя система.

yuracher commented 5 years ago

Do you maybe use some proxy from https to http? I had similar problem using docker + traefik. I fixed it by setting base url as absolute url with https.

uraankhayayaal commented 5 years ago

I have had the same problem. I didn`t change and update code, but I got this error in all of my project yesterday

SergeAntonets commented 5 years ago

unset($params['authuser']); unset($params['session_state']); unset($params['prompt']);

or set defaultUrl in config

Vashkatsi commented 5 years ago

Have the same problem, discovered yesturday. Update core and all packages, didn't help.

Does someone has a solution?

zlakomanoff commented 5 years ago
unset($params['authuser']);
unset($params['session_state']);
unset($params['prompt']);

looks like my fix still actual today :)

Pontorez commented 5 years ago
unset($params['authuser']);
unset($params['session_state']);
unset($params['prompt']);

looks like my fix still actual today :)

it doesn't help either

abigabaw commented 5 years ago

I also had to add unset($params['hd']) in addition to unsetting session_state, prompt and authuser.

Also, remember the format of the response ( $client->getUserAttributes() ) changed. Previous, to get the email address, you had $client->getUserAttributes()['emails'][0]['value'] but now it's simply $client->getUserAttributes()['email']. You can var_dump($client->getUserAttributes()) to see everything.

Vashkatsi commented 5 years ago
unset($params['authuser']);
unset($params['session_state']);
unset($params['prompt']);
unset($params['hd'])

This helped, thank ou guys.

Pilot1604 commented 5 years ago

Та же байда с гуглом - переходит на гугл, все подтверждаю и потом Exception – yii\authclient\InvalidResponseException Request failed with code: 400, message: { "error": "redirect_uri_mismatch", "error_description": "Bad Request" } in H:\OSPanel\domains\tselector.com\vendor\yiisoft\yii2-authclient\src\BaseOAuth.php at line 221 С Вконтакте тоже печаль - страница долго грузится а потом 404

samdark commented 5 years ago

@Pilot1604 попробуйте master.

Pilot1604 commented 5 years ago

@samdark Спасибо! Google заработал, а с вконтакте проблема осталась - никуда не переходит а просто страница долго грузится и потом 404, но может быть что этот домен локальный и работает через NoIp - чуть позже проверю на хостинге.

littletom1 commented 1 year ago

looks like auth urls is stuck (https://developers.google.com/identity/protocols/OAuth2WebServer) and need update OAuth2.php defaultReturnUrl method just add

unset($params['authuser']);
unset($params['session_state']);
unset($params['prompt']);

to unset block

easy money :)

works for me thank you a lot

DashaZayats commented 1 year ago
            'google' => [
                'class' => 'yii\authclient\clients\Google',
                'clientId' => '----------------',
                'clientSecret' => '--------------',
                'returnUrl' => 'https://yourdomain.com/site/auth?authclient=google', // add this row
            ],