1 | <?php |
||
23 | class Google extends AbstractProvider |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 3 | public function getBaseUri() |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 2 | public function getAuthorizeUri() |
|
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 2 | public function getRequestTokenUri() |
|
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 3 | public function getName() |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 3 | public function parseToken($body) |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 2 | public function getIdentity(AccessTokenInterface $accessToken) |
|
74 | { |
||
75 | 2 | $response = $this->httpClient->request( |
|
76 | 2 | $this->getBaseUri() . 'oauth2/v1/userinfo', |
|
77 | [ |
||
78 | 2 | 'access_token' => $accessToken->getToken() |
|
79 | 2 | ] |
|
80 | 2 | ); |
|
81 | |||
82 | 2 | if (!$response->isSuccess()) { |
|
83 | 1 | throw new InvalidResponse( |
|
84 | 1 | 'API response with error code', |
|
85 | $response |
||
86 | 1 | ); |
|
87 | } |
||
88 | |||
89 | 1 | $result = $response->json(); |
|
90 | 1 | if (!$result) { |
|
91 | 1 | throw new InvalidResponse( |
|
92 | 1 | 'API response is not a valid JSON object', |
|
93 | $response |
||
94 | 1 | ); |
|
95 | } |
||
96 | |||
97 | $hydrator = new ObjectMap( |
||
98 | [ |
||
99 | 'id' => 'id', |
||
100 | 'given_name' => 'firstname', |
||
101 | 'family_name' => 'lastname', |
||
102 | 'email' => 'email', |
||
103 | 'verified_email' => 'emailVerified', |
||
104 | 'name' => 'fullname', |
||
105 | 'gender' => 'sex', |
||
106 | ] |
||
107 | ); |
||
108 | |||
109 | return $hydrator->hydrate(new User(), $result); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function getScopeInline() |
||
119 | } |
||
120 |