Skip to content

Commit 68f5fb5

Browse files
authoredAug 21, 2020
Merge pull request hybridauth#1188 from Ganofins/patch-1
add DeviantArt Provider
2 parents 7e93ffd + 920ae93 commit 68f5fb5

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
 

‎src/Provider/DeviantArt.php

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
* DeviantArt OAuth2 provider adapter.
17+
*
18+
* Example:
19+
*
20+
* $config = [
21+
* 'callback' => Hybridauth\HttpClient\Util::getCurrentUrl(),
22+
* 'keys' => [ 'id' => '', 'secret' => '' ],
23+
* 'scope' => 'user',
24+
* ];
25+
*
26+
* $adapter = new Hybridauth\Provider\DeviantArt( $config );
27+
*
28+
* try {
29+
* $adapter->authenticate();
30+
*
31+
* $userProfile = $adapter->getUserProfile();
32+
* $tokens = $adapter->getAccessToken();
33+
* }
34+
* catch( Exception $e ){
35+
* echo $e->getMessage() ;
36+
* }
37+
*/
38+
class DeviantArt extends OAuth2
39+
{
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public $scope = 'user';
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protected $apiBaseUrl = 'https://www.deviantart.com/api/v1/oauth2/';
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected $authorizeUrl = 'https://www.deviantart.com/oauth2/authorize';
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
protected $accessTokenUrl = 'https://www.deviantart.com/oauth2/token';
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
protected $apiDocumentation = 'https://www.deviantart.com/developers/http/v1/20200519';
64+
65+
/**
66+
* {@inheritdoc}
67+
*/
68+
protected function initialize()
69+
{
70+
parent::initialize();
71+
72+
$this->tokenRefreshParameters += [
73+
'client_id' => $this->clientId,
74+
'client_secret' => $this->clientSecret,
75+
];
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*
81+
* See: https://www.deviantart.com/developers/http/v1/20200519/user_whoami/2413749853e66c5812c9beccc0ab3495
82+
*/
83+
public function getUserProfile()
84+
{
85+
$response = $this->apiRequest('user/whoami');
86+
87+
$data = new Data\Collection($response);
88+
89+
$userProfile = new User\Profile();
90+
91+
$full_name = explode(' ', $data->filter('profile')->get('real_name'));
92+
if (count($full_name) < 2) {
93+
$full_name[1] = '';
94+
}
95+
96+
$userProfile->identifier = $data->get('userid');
97+
$userProfile->displayName = $data->get('username');
98+
$userProfile->profileURL = $data->get('usericon');
99+
$userProfile->webSiteURL = $data->filter('profile')->get('website');
100+
$userProfile->firstName = $full_name[0];
101+
$userProfile->lastName = $full_name[1];
102+
$userProfile->profileURL = $data->filter('profile')->filter('profile_pic')->get('url');
103+
$userProfile->gender = $data->filter('details')->get('sex');
104+
$userProfile->age = $data->filter('details')->get('age');
105+
$userProfile->country = $data->filter('geo')->get('country');
106+
107+
return $userProfile;
108+
}
109+
}

0 commit comments

Comments
 (0)
Please sign in to comment.