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.
Merge pull request hybridauth#547 from ClassicCut/master
GitLab OAuth2 provider
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
additional-providers/hybridauth-gitlab/Providers/GitLab.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,51 @@ | ||
<?php | ||
|
||
/** | ||
* Hybrid_Providers_GitLab - GitLab.com provider adapter based on the OAuth2 protocol. | ||
*/ | ||
class Hybrid_Providers_GitLab extends Hybrid_Provider_Model_OAuth2 | ||
{ | ||
// default permissions | ||
// (no scope) => public read-only access (includes public user profile info, public repo info, and gists). | ||
public $scope = "api"; | ||
|
||
/** | ||
* IDp wrappers initializer | ||
*/ | ||
function initialize() | ||
{ | ||
parent::initialize(); | ||
|
||
// Provider api end-points | ||
$this->api->api_base_url = "https://gitlab.com/"; | ||
$this->api->authorize_url = "https://gitlab.com/oauth/authorize"; | ||
$this->api->token_url = "https://gitlab.com/oauth/token"; | ||
} | ||
|
||
/** | ||
* load the user profile from the IDp api client | ||
*/ | ||
function getUserProfile() | ||
{ | ||
$data = $this->api->api( "api/v3/user" ); | ||
|
||
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->displayName = @ $data->name; | ||
$this->user->profile->description = @ $data->bio; | ||
$this->user->profile->photoURL = @ $data->avatar_url; | ||
$this->user->profile->profileURL = @ $data->html_url; | ||
$this->user->profile->email = @ $data->email; | ||
$this->user->profile->webSiteURL = @ $data->website_ur; | ||
$this->user->profile->region = @ $data->location; | ||
|
||
if( empty($this->user->profile->displayName) ){ | ||
$this->user->profile->displayName = @ $data->username; | ||
} | ||
|
||
return $this->user->profile; | ||
} | ||
} |