Skip to content
This repository
Browse code

RIP Gowalla, adds Steam and Twitch.tv

  • Loading branch information...
commit 50e04c4c7a545f17b2d25807df839fb34d18642c 1 parent 909efca
hybridauth authored
102 additional-providers/hybridauth-gowalla/Providers/Gowalla.php
... ... @@ -1,102 +0,0 @@
1   -<?php
2   -/*!
3   -* HybridAuth
4   -* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
5   -* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
6   -*/
7   -
8   -/**
9   - * Hybrid_Providers_Gowalla provider adapter based on OAuth2 protocol
10   - *
11   - * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Gowalla.html
12   - */
13   -class Hybrid_Providers_Gowalla extends Hybrid_Provider_Model_OAuth2
14   -{
15   - /**
16   - * IDp wrappers initializer
17   - */
18   - function initialize()
19   - {
20   - parent::initialize();
21   -
22   - // Provider apis end-points
23   - $this->api->api_base_url = "https://api.gowalla.com/";
24   - $this->api->authorize_url = "https://gowalla.com/api/oauth/new";
25   - $this->api->token_url = "https://api.gowalla.com/api/oauth/token";
26   -
27   - $this->api->curl_header = array( 'X-Gowalla-API-Key: ' . $this->config["keys"]["id"], 'Accept: application/json' );
28   - }
29   -
30   - /**
31   - * load the user profile from the IDp api client
32   - */
33   - function getUserProfile()
34   - {
35   - // refresh tokens if needed
36   - $this->refreshToken();
37   -
38   - $data = $this->api->api( "users/me/" );
39   -
40   - if ( ! is_object( $data ) || ! isset( $data->username ) )
41   - {
42   - throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
43   - }
44   -
45   - $this->user->providerUID = @ (string) $data->username;
46   - $this->user->profile->firstName = @ (string) $data->first_name;
47   - $this->user->profile->lastName = @ (string) $data->last_name;
48   - $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName );
49   - $this->user->profile->profileURL = @ "http://gowalla.com" . ( (string) $data->url );
50   - $this->user->profile->webSiteURL = @ (string) $data->website;
51   - $this->user->profile->photoURL = @ (string) $data->image_url;
52   -
53   - // make sure to always have a display name
54   - if( ! $this->user->profile->displayName ){
55   - $this->user->profile->displayName = @ (string) $data->username;
56   - }
57   -
58   - return $this->user->profile;
59   - }
60   -
61   - function refreshToken()
62   - {
63   - // have an access token?
64   - if( $this->api->access_token ){
65   -
66   - // have to refresh?
67   - if( $this->api->refresh_token && $this->api->access_token_expires_at ){
68   -
69   - // expired?
70   - if( $this->api->access_token_expires_at <= time() ){
71   - $response = $this->api->refreshToken( array( "refresh_token" => $this->api->refresh_token, "access_token" => $this->api->access_token ) );
72   -
73   - if( ! isset( $response->access_token ) || ! $response->access_token ){
74   - // set the user as disconnected at this point and throw an exception
75   - $this->setUserUnconnected();
76   -
77   - throw new Exception( "The Authorization Service has return an invalid response while requesting a new access token. " . (string) $response->error );
78   - }
79   -
80   - // set new access_token
81   - $this->api->access_token = $response->access_token;
82   -
83   - if( isset( $response->refresh_token ) )
84   - $this->api->refresh_token = $response->refresh_token;
85   -
86   - if( isset( $response->expires_in ) ){
87   - $this->api->access_token_expires_in = $response->expires_in;
88   -
89   - // even given by some idp, we should calculate this
90   - $this->api->access_token_expires_at = time() + $response->expires_in;
91   - }
92   - }
93   - }
94   -
95   - // re store tokens
96   - $this->token( "access_token" , $this->api->access_token );
97   - $this->token( "refresh_token", $this->api->refresh_token );
98   - $this->token( "expires_in" , $this->api->access_token_expires_in );
99   - $this->token( "expires_at" , $this->api->access_token_expires_at );
100   - }
101   - }
102   -}
55 additional-providers/hybridauth-steam/Providers/Steam.php
... ... @@ -0,0 +1,55 @@
  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 + * Hybrid_Providers_Steam provider adapter based on OpenID protocol
  10 + *
  11 + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Steam.html
  12 + */
  13 +class Hybrid_Providers_Steam extends Hybrid_Provider_Model_OpenID
  14 +{
  15 + var $openidIdentifier = "http://steamcommunity.com/openid";
  16 +
  17 + /**
  18 + * finish login step
  19 + */
  20 + function loginFinish()
  21 + {
  22 + parent::loginFinish();
  23 +
  24 + $uid = str_replace( "http://steamcommunity.com/openid/id/", "", $this->user->profile->identifier );
  25 +
  26 + if( $uid ){
  27 + $data = @ file_get_contents( "http://steamcommunity.com/profiles/$uid/?xml=1" );
  28 +
  29 + $data = @ new SimpleXMLElement( $data );
  30 +
  31 + if ( ! is_object( $data ) ){
  32 + return false;
  33 + }
  34 +
  35 + $this->user->profile->displayName = (string) $data->{'steamID'};
  36 + $this->user->profile->photoURL = (string) $data->{'avatarMedium'};
  37 + $this->user->profile->description = (string) $data->{'summary'};
  38 +
  39 + $realname = (string) $data->{'realname'};
  40 +
  41 + if( $realname ){
  42 + $this->user->profile->displayName = $realname;
  43 + }
  44 +
  45 + $customURL = (string) $data->{'customURL'};
  46 +
  47 + if( $customURL ){
  48 + $this->user->profile->profileURL = "http://steamcommunity.com/id/$customURL/";
  49 + }
  50 +
  51 + // restore the user profile
  52 + Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.user", $this->user );
  53 + }
  54 + }
  55 +}
73 additional-providers/hybridauth-twitchtv/Providers/TwitchTV.php
... ... @@ -0,0 +1,73 @@
  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 + * Hybrid_Providers_TwitchTV provider adapter based on OAuth2 protocol
  10 + *
  11 + * http://hybridauth.sourceforge.net/userguide/IDProvider_info_TwitchTV.html
  12 + */
  13 +class Hybrid_Providers_TwitchTV extends Hybrid_Provider_Model_OAuth2
  14 +{
  15 + // default permissions
  16 + public $scope = "user_read channel_read";
  17 +
  18 + /**
  19 + * IDp wrappers initializer
  20 + */
  21 + function initialize()
  22 + {
  23 + parent::initialize();
  24 +
  25 + // Provider apis end-points
  26 + $this->api->api_base_url = "https://api.twitch.tv/kraken/";
  27 + $this->api->authorize_url = "https://api.twitch.tv/kraken/oauth2/authorize";
  28 + $this->api->token_url = "https://api.twitch.tv/kraken/oauth2/token";
  29 +
  30 + $this->api->sign_token_name = "oauth_token";
  31 + }
  32 +
  33 + /**
  34 + * begin login step
  35 + */
  36 + function loginBegin()
  37 + {
  38 + $parameters = array( "scope" => $this->scope );
  39 + $optionals = array( "scope" );
  40 +
  41 + foreach ($optionals as $parameter){
  42 + if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){
  43 + $parameters[$parameter] = $this->config[$parameter];
  44 + }
  45 + }
  46 +
  47 + Hybrid_Auth::redirect( $this->api->authorizeUrl( $parameters ) );
  48 + }
  49 +
  50 + /**
  51 + * load the user profile from the IDp api client
  52 + */
  53 + function getUserProfile()
  54 + {
  55 + $data = $this->api->api( "user" );
  56 +
  57 + if ( ! isset( $data->name ) ){
  58 + throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
  59 + }
  60 +
  61 + $this->user->profile->identifier = $data->_id;
  62 + $this->user->profile->displayName = $data->display_name;
  63 + $this->user->profile->photoURL = $data->logo;
  64 + $this->user->profile->profileURL = "http://www.twitch.tv/" . $data->name;
  65 + $this->user->profile->email = $data->email;
  66 +
  67 + if( ! $this->user->profile->displayName ){
  68 + $this->user->profile->displayName = $data->name;
  69 + }
  70 +
  71 + return $this->user->profile;
  72 + }
  73 +}

0 comments on commit 50e04c4

Please sign in to comment.
Something went wrong with that request. Please try again.