Permalink
Browse files

RIP Gowalla, adds Steam and Twitch.tv

  • Loading branch information...
1 parent 909efca commit 50e04c4c7a545f17b2d25807df839fb34d18642c hybridauth committed Jan 24, 2013
View
102 additional-providers/hybridauth-gowalla/Providers/Gowalla.php
@@ -1,102 +0,0 @@
-<?php
-/*!
-* HybridAuth
-* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
-* (c) 2009-2011 HybridAuth authors | hybridauth.sourceforge.net/licenses.html
-*/
-
-/**
- * Hybrid_Providers_Gowalla provider adapter based on OAuth2 protocol
- *
- * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Gowalla.html
- */
-class Hybrid_Providers_Gowalla extends Hybrid_Provider_Model_OAuth2
-{
- /**
- * IDp wrappers initializer
- */
- function initialize()
- {
- parent::initialize();
-
- // Provider apis end-points
- $this->api->api_base_url = "https://api.gowalla.com/";
- $this->api->authorize_url = "https://gowalla.com/api/oauth/new";
- $this->api->token_url = "https://api.gowalla.com/api/oauth/token";
-
- $this->api->curl_header = array( 'X-Gowalla-API-Key: ' . $this->config["keys"]["id"], 'Accept: application/json' );
- }
-
- /**
- * load the user profile from the IDp api client
- */
- function getUserProfile()
- {
- // refresh tokens if needed
- $this->refreshToken();
-
- $data = $this->api->api( "users/me/" );
-
- if ( ! is_object( $data ) || ! isset( $data->username ) )
- {
- throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
- }
-
- $this->user->providerUID = @ (string) $data->username;
- $this->user->profile->firstName = @ (string) $data->first_name;
- $this->user->profile->lastName = @ (string) $data->last_name;
- $this->user->profile->displayName = trim( $this->user->profile->firstName . " " . $this->user->profile->lastName );
- $this->user->profile->profileURL = @ "http://gowalla.com" . ( (string) $data->url );
- $this->user->profile->webSiteURL = @ (string) $data->website;
- $this->user->profile->photoURL = @ (string) $data->image_url;
-
- // make sure to always have a display name
- if( ! $this->user->profile->displayName ){
- $this->user->profile->displayName = @ (string) $data->username;
- }
-
- return $this->user->profile;
- }
-
- function refreshToken()
- {
- // have an access token?
- if( $this->api->access_token ){
-
- // have to refresh?
- if( $this->api->refresh_token && $this->api->access_token_expires_at ){
-
- // expired?
- if( $this->api->access_token_expires_at <= time() ){
- $response = $this->api->refreshToken( array( "refresh_token" => $this->api->refresh_token, "access_token" => $this->api->access_token ) );
-
- if( ! isset( $response->access_token ) || ! $response->access_token ){
- // set the user as disconnected at this point and throw an exception
- $this->setUserUnconnected();
-
- throw new Exception( "The Authorization Service has return an invalid response while requesting a new access token. " . (string) $response->error );
- }
-
- // set new access_token
- $this->api->access_token = $response->access_token;
-
- if( isset( $response->refresh_token ) )
- $this->api->refresh_token = $response->refresh_token;
-
- if( isset( $response->expires_in ) ){
- $this->api->access_token_expires_in = $response->expires_in;
-
- // even given by some idp, we should calculate this
- $this->api->access_token_expires_at = time() + $response->expires_in;
- }
- }
- }
-
- // re store tokens
- $this->token( "access_token" , $this->api->access_token );
- $this->token( "refresh_token", $this->api->refresh_token );
- $this->token( "expires_in" , $this->api->access_token_expires_in );
- $this->token( "expires_at" , $this->api->access_token_expires_at );
- }
- }
-}
View
55 additional-providers/hybridauth-steam/Providers/Steam.php
@@ -0,0 +1,55 @@
+<?php
+/*!
+* HybridAuth
+* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
+* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
+*/
+
+/**
+ * Hybrid_Providers_Steam provider adapter based on OpenID protocol
+ *
+ * http://hybridauth.sourceforge.net/userguide/IDProvider_info_Steam.html
+ */
+class Hybrid_Providers_Steam extends Hybrid_Provider_Model_OpenID
+{
+ var $openidIdentifier = "http://steamcommunity.com/openid";
+
+ /**
+ * finish login step
+ */
+ function loginFinish()
+ {
+ parent::loginFinish();
+
+ $uid = str_replace( "http://steamcommunity.com/openid/id/", "", $this->user->profile->identifier );
+
+ if( $uid ){
+ $data = @ file_get_contents( "http://steamcommunity.com/profiles/$uid/?xml=1" );
+
+ $data = @ new SimpleXMLElement( $data );
+
+ if ( ! is_object( $data ) ){
+ return false;
+ }
+
+ $this->user->profile->displayName = (string) $data->{'steamID'};
+ $this->user->profile->photoURL = (string) $data->{'avatarMedium'};
+ $this->user->profile->description = (string) $data->{'summary'};
+
+ $realname = (string) $data->{'realname'};
+
+ if( $realname ){
+ $this->user->profile->displayName = $realname;
+ }
+
+ $customURL = (string) $data->{'customURL'};
+
+ if( $customURL ){
+ $this->user->profile->profileURL = "http://steamcommunity.com/id/$customURL/";
+ }
+
+ // restore the user profile
+ Hybrid_Auth::storage()->set( "hauth_session.{$this->providerId}.user", $this->user );
+ }
+ }
+}
View
73 additional-providers/hybridauth-twitchtv/Providers/TwitchTV.php
@@ -0,0 +1,73 @@
+<?php
+/*!
+* HybridAuth
+* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
+* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
+*/
+
+/**
+ * Hybrid_Providers_TwitchTV provider adapter based on OAuth2 protocol
+ *
+ * http://hybridauth.sourceforge.net/userguide/IDProvider_info_TwitchTV.html
+ */
+class Hybrid_Providers_TwitchTV extends Hybrid_Provider_Model_OAuth2
+{
+ // default permissions
+ public $scope = "user_read channel_read";
+
+ /**
+ * IDp wrappers initializer
+ */
+ function initialize()
+ {
+ parent::initialize();
+
+ // Provider apis end-points
+ $this->api->api_base_url = "https://api.twitch.tv/kraken/";
+ $this->api->authorize_url = "https://api.twitch.tv/kraken/oauth2/authorize";
+ $this->api->token_url = "https://api.twitch.tv/kraken/oauth2/token";
+
+ $this->api->sign_token_name = "oauth_token";
+ }
+
+ /**
+ * begin login step
+ */
+ function loginBegin()
+ {
+ $parameters = array( "scope" => $this->scope );
+ $optionals = array( "scope" );
+
+ foreach ($optionals as $parameter){
+ if( isset( $this->config[$parameter] ) && ! empty( $this->config[$parameter] ) ){
+ $parameters[$parameter] = $this->config[$parameter];
+ }
+ }
+
+ Hybrid_Auth::redirect( $this->api->authorizeUrl( $parameters ) );
+ }
+
+ /**
+ * load the user profile from the IDp api client
+ */
+ function getUserProfile()
+ {
+ $data = $this->api->api( "user" );
+
+ if ( ! isset( $data->name ) ){
+ 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->display_name;
+ $this->user->profile->photoURL = $data->logo;
+ $this->user->profile->profileURL = "http://www.twitch.tv/" . $data->name;
+ $this->user->profile->email = $data->email;
+
+ if( ! $this->user->profile->displayName ){
+ $this->user->profile->displayName = $data->name;
+ }
+
+ return $this->user->profile;
+ }
+}

0 comments on commit 50e04c4

Please sign in to comment.