1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
* (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
*/
/**
* Hybrid_Providers_Dropbox provider adapter based on OAuth2 protocol
*
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_Dropbox.html
*/
class Hybrid_Providers_Dropbox extends Hybrid_Provider_Model_OAuth2
{
/**
* IDp wrappers initializer
*/
function initialize()
{
parent::initialize();
// Provider apis end-points
$this->api->api_base_url = "https://api.dropbox.com/1/";
$this->api->authorize_url = "https://www.dropbox.com/1/oauth2/authorize";
$this->api->token_url = "https://api.dropbox.com/1/oauth2/token";
}
/**
* load the user profile from the IDp api client
*/
function getUserProfile()
{
// refresh tokens if needed
$this->refreshToken();
try{
$response = $this->api->api( "account/info" );
}
catch( DropboxException $e ){
throw new Exception( "User profile request failed! {$this->providerId} returned an error: $e", 6 );
}
// check the last HTTP status code returned
if ( $this->api->http_code != 200 ){
throw new Exception( "User profile request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ), 6 );
}
if ( ! is_object( $response ) || ! isset( $response->uid ) ){
throw new Exception( "User profile request failed! {$this->providerId} api returned an invalid response.", 6 );
}
# store the user profile.
$this->user->profile->identifier = (property_exists($response,'uid'))?$response->uid:"";
$this->user->profile->profileURL = "";
$this->user->profile->webSiteURL = "";
$this->user->profile->photoURL = "";
$this->user->profile->displayName = (property_exists($response,'display_name'))?$response->display_name:"";
$this->user->profile->description = "";
$this->user->profile->firstName = (property_exists($response,'name_details'))?(property_exists($response->name_details,'given_name'))?$response->name_details->given_name:"":"";
$this->user->profile->lastName = (property_exists($response,'name_details'))?(property_exists($response->name_details,'surname'))?$response->name_details->surname:"":"";
$this->user->profile->gender = "";
$this->user->profile->language = "";
$this->user->profile->age = "";
$this->user->profile->birthDay = "";
$this->user->profile->birthMonth = "";
$this->user->profile->birthYear = "";
$this->user->profile->email = (property_exists($response,'email'))?$response->email:"";
$this->user->profile->emailVerified = "";
if ( property_exists($response,'email_verified') ) {
if ( $response->email_verified ) {
$this->user->profile->emailVerified = $this->user->profile->email;
}
}
$this->user->profile->phone = "";
$this->user->profile->address = "";
$this->user->profile->country = (property_exists($response,'country'))?$response->country:"";
$this->user->profile->region = "";
$this->user->profile->city = "";
$this->user->profile->zip = "";
return $this->user->profile;
}
}
|