source: extensions/oAuth/include/hybridauth/Hybrid/Providers/Live.php @ 20293

Last change on this file since 20293 was 20293, checked in by mistic100, 11 years ago

first commit of oAuth plugin, still in developpement

File size: 3.3 KB
Line 
1<?php
2/*!
3* HybridAuth
4* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6*/
7
8/**
9 * Windows Live OAuth2 Class
10 *
11 * @package             HybridAuth providers package
12 * @author              Lukasz Koprowski <azram19@gmail.com>
13 * @version             0.2
14 * @license             BSD License
15 */ 
16
17/**
18 * Hybrid_Providers_Live - Windows Live provider adapter based on OAuth2 protocol
19 */
20class Hybrid_Providers_Live extends Hybrid_Provider_Model_OAuth2
21{
22        // default permissions
23        public $scope = "wl.basic wl.emails wl.signin wl.share wl.birthday";
24
25       
26        /**
27        * IDp wrappers initializer
28        */
29        function initialize() 
30        {
31                parent::initialize();
32
33                // Provider api end-points
34                $this->api->api_base_url  = 'https://apis.live.net/v5.0/';
35                $this->api->authorize_url = 'https://login.live.com/oauth20_authorize.srf';
36                $this->api->token_url     = 'https://login.live.com/oauth20_token.srf';
37
38                $this->api->curl_authenticate_method  = "GET";
39        }
40
41        /**
42        * grab the user profile from the api client
43        */
44        function getUserProfile()
45        {
46                $data = $this->api->get( "me" ); 
47
48                if ( ! isset( $data->id ) ){
49                        throw new Exception( "User profile request failed! {$this->providerId} returned an invalide response.", 6 );
50                }
51
52                $this->user->profile->identifier    = (property_exists($data,'id'))?$data->id:"";
53                $this->user->profile->firstName     = (property_exists($data,'first_name'))?$data->first_name:"";
54                $this->user->profile->lastName      = (property_exists($data,'last_name'))?$data->last_name:"";
55                $this->user->profile->displayName   = (property_exists($data,'name'))?trim( $data->name ):"";
56                $this->user->profile->gender        = (property_exists($data,'gender'))?$data->gender:"";
57
58                //wl.basic
59                $this->user->profile->profileURL    = (property_exists($data,'link'))?$data->link:"";
60
61                //wl.emails
62                $this->user->profile->email         = (property_exists($data,'emails'))?$data->emails->account:"";
63                $this->user->profile->emailVerified = (property_exists($data,'emails'))?$data->emails->account:"";
64
65                //wl.birthday
66                $this->user->profile->birthDay      = (property_exists($data,'birth_day'))?$data->birth_day:"";
67                $this->user->profile->birthMonth    = (property_exists($data,'birth_month'))?$data->birth_month:"";
68                $this->user->profile->birthYear     = (property_exists($data,'birth_year'))?$data->birth_year:"";
69
70                return $this->user->profile;
71        }
72
73
74        /**
75        * load the current logged in user contacts list from the IDp api client 
76        */
77
78        /* Windows Live api does not support retrieval of email addresses (only hashes :/) */
79        function getUserContacts() 
80        {
81                $response = $this->api->get( 'me/contacts' );
82
83                if ( $this->api->http_code != 200 )
84                {
85                        throw new Exception( 'User contacts request failed! ' . $this->providerId . ' returned an error: ' . $this->errorMessageByStatus( $this->api->http_code ) );
86                }
87
88                if ( ! $response->data && ( $response->error != 0 ) )
89                {
90                        return array();
91                }
92               
93                $contacts = array();
94
95                foreach( $response->data as $item ) {
96                        $uc = new Hybrid_User_Contact();
97
98                        $uc->identifier   = (property_exists($item,'id'))?$item->id:"";
99                        $uc->displayName  = (property_exists($item,'name'))?$item->name:"";
100
101                        $contacts[] = $uc;
102                }
103               
104                return $contacts;
105        }
106}
Note: See TracBrowser for help on using the repository browser.