PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/additional-providers/hybridauth-gitlab/Providers/GitLab.php

https://gitlab.com/loic-corbasson/hybridauth
PHP | 51 lines | 31 code | 8 blank | 12 comment | 2 complexity | afcc3e4b045c5aeb359f0a4be021a9ca MD5 | raw file
  1. <?php
  2. /**
  3. * Hybrid_Providers_GitLab - GitLab.com provider adapter based on the OAuth2 protocol.
  4. */
  5. class Hybrid_Providers_GitLab extends Hybrid_Provider_Model_OAuth2
  6. {
  7. // default permissions
  8. // (no scope) => public read-only access (includes public user profile info, public repo info, and gists).
  9. public $scope = "api";
  10. /**
  11. * IDp wrappers initializer
  12. */
  13. function initialize()
  14. {
  15. parent::initialize();
  16. // Provider api end-points
  17. $this->api->api_base_url = "https://gitlab.com/";
  18. $this->api->authorize_url = "https://gitlab.com/oauth/authorize";
  19. $this->api->token_url = "https://gitlab.com/oauth/token";
  20. }
  21. /**
  22. * load the user profile from the IDp api client
  23. */
  24. function getUserProfile()
  25. {
  26. $data = $this->api->api( "api/v3/user" );
  27. if ( ! isset( $data->id ) ){
  28. throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
  29. }
  30. $this->user->profile->identifier = @ $data->id;
  31. $this->user->profile->displayName = @ $data->name;
  32. $this->user->profile->description = @ $data->bio;
  33. $this->user->profile->photoURL = @ $data->avatar_url;
  34. $this->user->profile->profileURL = @ $data->html_url;
  35. $this->user->profile->email = @ $data->email;
  36. $this->user->profile->webSiteURL = @ $data->website_ur;
  37. $this->user->profile->region = @ $data->location;
  38. if( empty($this->user->profile->displayName) ){
  39. $this->user->profile->displayName = @ $data->username;
  40. }
  41. return $this->user->profile;
  42. }
  43. }