Skip to content
This repository was archived by the owner on Oct 14, 2022. It is now read-only.

Commit 33eeb89

Browse files
committed
fix bug with Google auth in the budyaga\users\components\oauth\Google
1 parent 1fde865 commit 33eeb89

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ Password: yii2shortenerpassword
3939
* Add to file `app/config/web-local.php` your oauth data, for example:
4040
```php
4141
<?php
42-
use budyaga\users\components\oauth\Google;
43-
4442
return [
4543
'components' => [
4644
'authClientCollection' => [
4745
'clients' => [
4846
'google' => [
49-
'class' => Google::class,
47+
'class' => 'app\components\oauth\Google',
48+
'clientId' => 'XXX',
49+
'clientSecret' => 'XXX',
50+
],
51+
'facebook' => [
52+
'class' => 'budyaga\users\components\oauth\Facebook',
5053
'clientId' => 'XXX',
5154
'clientSecret' => 'XXX',
5255
],

app/components/oauth/Google.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace app\components\oauth;
4+
5+
use budyaga\users\models\User;
6+
use budyaga\users\models\UserOauthKey;
7+
8+
/**
9+
* Fix error with incorrect API request in initUserAttributes
10+
* @override budyaga\users\components\oauth\Google
11+
*/
12+
class Google extends \yii\authclient\clients\Google
13+
{
14+
/**
15+
* @inheritdoc
16+
*/
17+
public function getViewOptions()
18+
{
19+
return [
20+
'popupWidth' => 900,
21+
'popupHeight' => 500
22+
];
23+
}
24+
25+
public function normalizeSex()
26+
{
27+
return [
28+
'male' => User::SEX_MALE,
29+
'female' => User::SEX_FEMALE
30+
];
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function init()
37+
{
38+
parent::init();
39+
if ($this->scope === null) {
40+
$this->scope = implode(' ', [
41+
'profile',
42+
'email',
43+
]);
44+
}
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function initUserAttributes()
51+
{
52+
$attributes = parent::initUserAttributes();
53+
54+
$return_attributes = [
55+
'User' => [
56+
'email' => $attributes['email'],
57+
'username' => $attributes['name'],
58+
'photo' => $attributes['picture'],
59+
'sex' => 1 //empty information from Google
60+
],
61+
'provider_user_id' => $attributes['id'],
62+
'provider_id' => UserOauthKey::getAvailableClients()['google'],
63+
];
64+
65+
return $return_attributes;
66+
}
67+
}

0 commit comments

Comments
 (0)