This repository was archived by the owner on Oct 14, 2022. It is now read-only.
File tree 2 files changed +73
-3
lines changed
2 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -39,14 +39,17 @@ Password: yii2shortenerpassword
39
39
* Add to file ` app/config/web-local.php ` your oauth data, for example:
40
40
``` php
41
41
<?php
42
- use budyaga\users\components\oauth\Google;
43
-
44
42
return [
45
43
'components' => [
46
44
'authClientCollection' => [
47
45
'clients' => [
48
46
'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',
50
53
'clientId' => 'XXX',
51
54
'clientSecret' => 'XXX',
52
55
],
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments