forked from coldfrontlabs/hybridauth-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add strava as new provider
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
additional-providers/hybridauth-strava/Providers/strava.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* Hybrid_Providers_Strava | ||
*/ | ||
class Hybrid_Providers_Strava extends Hybrid_Provider_Model_OAuth2 | ||
{ | ||
// default permissions | ||
public $scope = "public"; | ||
|
||
/** | ||
* IDp wrappers initializer | ||
*/ | ||
function initialize() | ||
{ | ||
parent::initialize(); | ||
|
||
// Provider api end-points | ||
$this->api->api_base_url = "https://www.strava.com/api/v3/"; | ||
$this->api->authorize_url = "https://www.strava.com/oauth/authorize"; | ||
$this->api->token_url = "https://www.strava.com/oauth/token"; | ||
|
||
} | ||
|
||
/** | ||
* load the user profile from the IDp api client | ||
*/ | ||
function getUserProfile(){ | ||
$data = $this->api->get("athlete"); | ||
|
||
if ( ! isset( $data->id ) ){ | ||
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 ); | ||
} | ||
|
||
$this->user->profile->identifier = $data->id; | ||
$this->user->profile->username = $data->username; | ||
$this->user->profile->displayName = $data->firstname.' '.$data->lastname; | ||
$this->user->profile->photoURL = $data->profile_medium; | ||
$this->user->profile->profileURL = 'https://www.strava.com/athletes/'.$data->id; | ||
$this->user->profile->email = $data->email; | ||
$this->user->profile->emailVerified = $data->email; | ||
$this->user->profile->gender = $data->sex; | ||
$this->user->profile->city = array_key_exists('city', $data)?$data->city:''; | ||
$this->user->profile->state = array_key_exists('state', $data)?$data->state:''; | ||
$this->user->profile->country = array_key_exists('country', $data)?$data->country:''; | ||
|
||
return $this->user->profile; | ||
} | ||
|
||
} |