Skip to content

Commit

Permalink
Add strava as new provider
Browse files Browse the repository at this point in the history
Add strava as new provider
  • Loading branch information
StorytellerCZ authored Oct 9, 2016
2 parents 1de5445 + cc1c4f7 commit f0c4e2c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions additional-providers/hybridauth-strava/Providers/strava.php
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;
}

}

0 comments on commit f0c4e2c

Please sign in to comment.