@@ 52-78 (lines=27) @@ | ||
49 | /** |
|
50 | * {@inheritdoc} |
|
51 | */ |
|
52 | public function identify(oauth2\Token $token) : Promise |
|
53 | { |
|
54 | $promise = $this->request('GET', $this->getIdentifyUrl(), $token); |
|
55 | ||
56 | // Bitbucket, similar to GitHub, makes an entity's e-mail addresses available at a different endpoint, |
|
57 | // so if we are asked to fetch it, let's run that request in parallel to save some time on HTTP roundtrips. |
|
58 | if ($this->shouldProvideEmailAddress()) { |
|
59 | ||
60 | // Intercept the flow - instead of directly returning a Promise for the entity's identity data, |
|
61 | // we will now return a Promise that resolves once both the email and identity |
|
62 | // data have been resolved and the email has been mapped into the identity data. |
|
63 | $promise = $this->getEmail($token)->then(function ($email) use ($token, $promise) { |
|
64 | ||
65 | // Map the email in once the identity data is available (has succesfully resolved). |
|
66 | return $promise->then(function (array $data) use ($token, $email) { |
|
67 | ||
68 | $data['email'] = $email ?? $data['email']; |
|
69 | ||
70 | return $data; |
|
71 | }); |
|
72 | }); |
|
73 | } |
|
74 | ||
75 | return $promise->then(function (array $data) use ($token) { |
|
76 | return $this->createIdentity($token, $data); |
|
77 | }); |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * Returns a Promise for the e-mail address (primary and verified) belonging to the entity whose Access Token |
@@ 47-73 (lines=27) @@ | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function identify(oauth2\Token $token) : Promise |
|
48 | { |
|
49 | $promise = $this->request('GET', $this->getIdentifyUrl(), $token); |
|
50 | ||
51 | // GitHub makes an entity's e-mail addresses available at a different endpoint, so if we are asked |
|
52 | // to fetch it, let's run that request in parallel to save some time on HTTP roundtrips. |
|
53 | if ($this->shouldProvideEmailAddress()) { |
|
54 | ||
55 | // Intercept the flow - instead of directly returning a Promise for the entity's identity data, |
|
56 | // we will now return a Promise that resolves once both the email and identity |
|
57 | // data have been resolved and the email has been mapped into the identity data. |
|
58 | $promise = $this->getEmail($token)->then(function ($email) use ($token, $promise) { |
|
59 | ||
60 | // Map the e-mail address in once the identity data is available (has successfully resolved). |
|
61 | return $promise->then(function (array $data) use ($token, $email) { |
|
62 | ||
63 | $data['email'] = $email ?? $data['email']; |
|
64 | ||
65 | return $data; |
|
66 | }); |
|
67 | }); |
|
68 | } |
|
69 | ||
70 | return $promise->then(function (array $data) use ($token) { |
|
71 | return $this->createIdentity($token, $data); |
|
72 | }); |
|
73 | } |
|
74 | ||
75 | /** |
|
76 | * Returns a Promise for the e-mail address (primary and verified) belonging to the entity whose Access Token |