Skip to content

Commit 222ab4e

Browse files
authored
Merge pull request hybridauth#1251 from Ganofins/patch-1
add provider Medium
2 parents 488c2bf + 119318b commit 222ab4e

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/Provider/Medium.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/*!
3+
* Hybridauth
4+
* https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
5+
* (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
6+
*/
7+
8+
namespace Hybridauth\Provider;
9+
10+
use Hybridauth\Adapter\OAuth2;
11+
use Hybridauth\Exception\UnexpectedApiResponseException;
12+
use Hybridauth\Data;
13+
use Hybridauth\User;
14+
15+
/**
16+
* Medium OAuth2 provider adapter.
17+
*/
18+
class Medium extends OAuth2
19+
{
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
protected $scope = 'basicProfile';
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
protected $apiBaseUrl = 'https://api.medium.com/v1/';
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
protected $authorizeUrl = 'https://medium.com/m/oauth/authorize';
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected $accessTokenUrl = 'https://api.medium.com/v1/tokens';
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs';
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protected function initialize()
49+
{
50+
parent::initialize();
51+
52+
if ($this->isRefreshTokenAvailable()) {
53+
$this->tokenRefreshParameters += [
54+
'client_id' => $this->clientId,
55+
'client_secret' => $this->clientSecret,
56+
];
57+
}
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*
63+
* See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details
64+
*/
65+
public function getUserProfile()
66+
{
67+
$response = $this->apiRequest('me');
68+
69+
$data = new Data\Collection($response);
70+
71+
$userProfile = new User\Profile();
72+
$data = $data->filter('data');
73+
74+
$full_name = explode(' ', $data->get('name'));
75+
if (count($full_name) < 2) {
76+
$full_name[1] = '';
77+
}
78+
79+
$userProfile->identifier = $data->get('id');
80+
$userProfile->displayName = $data->get('username');
81+
$userProfile->profileURL = $data->get('imageUrl');
82+
$userProfile->firstName = $full_name[0];
83+
$userProfile->lastName = $full_name[1];
84+
$userProfile->profileURL = $data->get('url');
85+
86+
return $userProfile;
87+
}
88+
}

0 commit comments

Comments
 (0)