Oauth open protocol, all about web 2.0 authentications …

Nowadays, Most web applications are using the Oauth open protocol to get rid of the boring subscription processes, so when the application is authorized by the user (who gives his credentials, usually username & password), Oauth guarantees a secure access to his private informations like (photos, videos, contacts list, …etc) by handling tokens, without revealing his identity. Among these applications we can find facebook, twitter, linkdin, gmail and Yahoo! … I’ll try to give you through this article a full explanation of the process

and code working on both local and hosted web applications. examples below will be about facebook and twitter Oauth process always under symfony framework.

The first step is to create an application for both facebook & twitter, This process provide many keys (Application ID, Secret …etc)

which are used to define your application. It’s important for facebook that the connect url must have the same prefix as your application (Server name). We don’t have this problem using Twitter. Another comparison. After authentication, facebook redirect you to the refer page whereas Twitter needs a callback url who doesn’t allow access from local web applications. No matter, we will use a personalized callback url.

To start with code, we’ll first have to create a new symfony model, project and application. Our example will be about visitors log where username, facebook or twitter user ID and the time_visit information will be saved on our database.

#schema.yml
TbOauth:
actAs: { Timestampable: ~ }
columns:
log_id:  { type: integer, notnull: true, primary: true, autoincrement: true }
user_id:  { type: integer, notnull: true, primary: false }
user_name:  { type: string(255), primary: false }

After downloading Symfony, Copy the zip file into the directory containing the previous schema.yml file, then execute the following script …

mkdir -p lib/vendor
cp symfony-1.4.6.zip lib/vendor
cd lib/vendor
unzip symfony-1.4.6.zip
mv symfony-1.4.6 symfony
cd ../..
php lib/vendor/symfony/data/bin/symfony generate:project oauth
chmod -R 777 cache
chmod -R 777 log
php symfony generate:app frontend
mysqladmin -h localhost -u {username} -p{password} create oauth
php symfony configure:database “mysql:host=localhost;dbname=oauth” {username} {password}
cp schema.yml config/doctrine/
php symfony doctrine:build-model
php symfony doctrine:build-sql
php symfony doctrine:insert-sql
php symfony doctrine:build-forms
php symfony doctrine:generate-module frontend oauth TbOauth

Nice, The project have been created, you’ll then have to stock the Oauth keys in the app.yml for a global use. You’ll also need the API scripts for both (facebook.php & _twitter.php), extract all to frontend/module/oauth/templates folder to be able to use them as partials. If you want to use them from other modules you’ll have to integrate them using the sfUser class.

#frontend/config/app.yml
all:
facebook_id: 13539xxxxxxx
facebook_secret: 92a9decc9b95exxxxxxxxxxxxxx
twitter_id: iSzcySy7setxxxxxxxxxxxxxx
twitter_secret: 5CYop3cEB3I1Fc4lvSy0XxxxxxxxxxxxG4ImmM

Something you also must know, our code uses cookies for the facebook Oauth so we will need a logout url to clear them after logout whereas the sfUser class stock and let us access the user status for Twitter.

Here are the code I used to perform these authentication processes …

#frontend/templates/indexSuccess.php
<?php include_partial(‘facebook’) ?>

<?php $facebook = new Facebook(array(
‘appId’  => sfConfig::get(‘app_facebook_id’),
‘secret’ => sfConfig::get(‘app_facebook_secret’),
‘cookie’ => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api(‘/me’);
} catch (FacebookApiException $e) {
error_log($e);
}

}

$url_fb_out = $facebook->getLogoutUrl();
$url_fb_in = $facebook->getLoginUrl();

if($me)
{
echo ‘<a href=”‘.$url_fb_out.’”>Logout</a>’;
if($sf_user->getAttribute(‘state’)!=’in’)
{
$user=new TbOauth();
$user->setUserId($uid);
$user->setUserName($me['name']);
$user->save();
$sf_user->setAttribute(‘state’,'in’);
header(“Location: “.url_for(‘oauth/index’));
exit;
}
}
else
{
$sf_user->setAttribute(‘state’,'out’);
echo ‘<a href=”‘.$url_fb_in.’”>Login</a>’;
}
?>

<?php include_partial(‘log’,array(‘tb_oauths’=>$tb_oauths)) ?>

#frontend/templates/indexSuccess.php
<?php include_partial(‘twitter’) ?>

<?php
if($sf_request->hasParameter(‘logout’))
$sf_user->setAttribute(‘state’,'out’);

if($sf_user->getAttribute(‘state’)==’in’)
echo ‘<a href=”‘.url_for(‘oauth/index’).’?logout=1″>Logout</a>’;

/** After calling back we should have these two parameters (oauth_token & oauth_verifier) */
if($sf_request->hasParameter(‘oauth_token’) & $sf_request->hasParameter(‘oauth_verifier’))
{
$obj = new TwitterAPI(sfConfig::get(‘app_twitter_id’), sfConfig::get(‘app_twitter_secret’),
$sf_user->getAttribute(‘oauth_token’),$sf_user->getAttribute(‘oauth_token_secret’));
$access_token = $obj->getAccessToken($sf_request->getParameter(‘oauth_verifier’));
if(!$access_token)
{
echo ‘error’;
die();
}
$user=new TbOauth();
$user->setUserId($access_token['user_id']);
$user->setUserName($access_token['screen_name']);
$user->save();
$sf_user->setAttribute(‘state’,'in’);
header(“Location: “.url_for(‘oauth/index’));
exit;
}
else
{
$connection = new TwitterAPI(sfConfig::get(‘app_twitter_id’), sfConfig::get(‘app_twitter_secret’));
$request_token = $connection->getRequestToken($sf_request->getUri());
$sf_user->setAttribute(‘oauth_token’,$request_token['oauth_token']);
$sf_user->setAttribute(‘oauth_token_secret’,$request_token['oauth_token_secret']);
$url_tw = $connection->getLoginURL($request_token);
if($sf_user->getAttribute(‘state’)!=’in’)
echo ‘<a href=”‘.$url_tw.’”>Login</a>’;
}
?>

<?php include_partial(‘log’,array(‘tb_oauths’=>$tb_oauths)) ?>

#frontend/templates/_log.php
<table border=1 align=’center’>
<thead>
<tr>
<th width=200>User ID</th>
<th width=200>User name</th>
<th width=200>Last visit</th>
</tr>
</thead>
<tbody>
<?php foreach ($tb_oauths as $tb_oauth): ?>
<tr>
<td><?php echo $tb_oauth->getUserId() ?></td>
<td><?php echo $tb_oauth->getUserName() ?></td>
<td><?php echo $tb_oauth->getCreatedAt() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

Final Thoughts …

From now and on, no more subscriptions nor filling a lot of boring fields, all we need is the user credentials for any Oauth then have just to retrieve  the user_id & username (The displayed name) that will be used as parameters for the APIs, so you can get the rest of your user profile informations, it’s really simple, check about: http://developers.facebook.com/docs/api and http://dev.twitter.com/doc for more details. The two lines below give you access to my facebook and twitter profile images …
http://graph.facebook.com/lmseddik/picture
http://api.twitter.com/1/users/profile_image/twitter.json?screen_name=lmseddik.


Bookmark and Share

Hi-Tech & Web upcoming large scale events !

I’ve selected some of the most important upcoming Hi-tech, Web and Social events. and because I  couldn’t talk about all what will happen during the next 6 month, I’ve only chosen the three I’m more interested in, I’ll try to give you a brief presentation about each one.. so, If you think about another ones… please, don’t hesitate, just leave a comment! all the community will appreciate, so let’s start ..

For those who don’t use a Linux distribution, you can skip this first one, just scroll down and check about the next one. The others, like me, will certainly be really excited to check about :

LinuxCon brings together the best and brightest that the Linux community has to offer, including core developers, administrators, end users, business executives and operations experts – the best technical talent and the decision makers and industry experts who are involved in the Linux community.

The last conference was held in Portland during last September. The next one will took place in Renaissance Boston Waterfront, Boston, MA, the 10th August 2010, check out here the schedule for LinuxCon 2010.


As shown in the previous video, you can meet there the smartest and the most talented guys from Linux comunity. keynotes,round tables and more than 50 conference sessions are organized. Check Here about keynote speaker for the next session

Software developer, especialy those using a linux destribution, Linux IT professional and student will certainly apprecite beeing there.

Let’s talk now about an online event,

BrightTalk summit, or how to use social media to promote your small business! providing live webcasts presentation performed by marketing experts, talking about social media tools and their importance when rising your small business.

If you want, you can only choose the webcasts you’re more interested in. all the webcasts are available online. don’t wast your time, just go online and check about the next 9th July topics. It’ll talk about server virtualization, intrusion prevention managing cloud services, 2.0 ITs and a lot of interesting topics. Check here about the last (2009) session webcasts …


With more than 2500 participants from 50 countries, LE WEB is considered as the first Internet European Event!




The next session will took place in Les Docs,Paris, the 8th and 9th December, just see the presentation made by Loic Lemeur and his wife Geraldine, talking about next session topics:

I never attended this event, but I’ve already fellow sessions online, I advice you to check about Chris Pirillo (founder Lockergnome) and Tony Hsiel (zappos.com CEO) talks during the last session

I don’t think you can actually find in France a better place to meet the best entrepreneurs, startupers in Europe.
If you’re new entrepreneur, The StartUp Competition will certainly interest you, like what organizers said: “it’s a great opportunity for rising stars to get more visibility in front of business leaders, investors and technology influencers”

Final Thoughts …

LinuxCon,BrightTalk and LeWeb are the most important event I’m waiting for, but there is a lot of others, so if you’re thinking about another ones, just leave a comment! all the community will appreciate …


Bookmark and Share

Location-based social networks: new Emerging startups …

Like Twitter, Foursquare, Plyce and a lot of new social networks, many others are emerging : I’ll specially talk about what I consider as a new tendency or more specially which announce a new social networking era.

See what your friends are doing and where they are ?

Unlike the old social networks, these new ones offer many other ways to check about your friends, being in touch with them, sharing more and more informations. not only about people but also about places, writing places histories and creating feeds between people and places .
All these new Localization-based social services offer new social sharing ways … let’s see some of them :

Here are some of the new imerging Localization-based startups I like :

Foursquare : Find your friends, unlock your city

Created by Dennis Crowley and Naveen Selvadurai. With foursquare , your can find friends , check about where they are hanging out, explore your city and also earn points & unlock badges for discovering new things …

take a look at this video, it shows foursquare services :

Like what they said, for using foursquare you just need a cell phone (it’s available for IPhone, Blackberry, Android , Palms and other devices) and a passion for exploration…
With foursquare, you can easily add not listed places, sharing you own social places experiences , the more you use it the more you extend your social experience. Foursquare mix social , location and gaming elements …

Find here Dennis Crowley foursquare co-founder talking about (How to make the world more fun or how to turn it into video game) … really interesting

Like facebook ,foursquare provide a usefull API, helping developers easily creating foursquare APPs


Plyce : See friends in common with people arround …


As Martin Destagol (Plyce Founder) said, this new emerging french startup creats interractions between people and places.
Helping people find friends, checking about them, where they are, what they are doing?
Plyce let you know all about places, by writing places histories , users provide and share informations about their personal experiences.
Before visiting a market place, a restaurant, a museum or other places, just check about users opinion and make the best choice.

With Plyce, you can know where your friends are, what they are doing? justing by checking about them using your Plyce account. You can also easily manage your confidentiality, sharing only about the people you like…

With people sharing comments, posting photos, brands and places can easily be promoted using Plyce.


Google latitude

Google latitude is available for phones and computers, it lets you see your friends on a map. With their real time localization services, you can know easily where your friends are? contact them, control your location and so on.

Find here more informations about the service …

Nomao, The Local Search Engine which is getting worldwide to spread out results based on what we like


Created by Frederic Montagnon (OverBlog Co-Founder) and his team, it’s Also based on interractions between peoples and places, They provide a local search Engine which help you easily find places, places peoples liked, you can also only check about your friends opinion
Nomao also provide an augmented reality services, helping you easily find places just arround the corner
I personally like this service, Just click here, and try it, it’s really usefull

Final Thoughts ….

A lot of other based-Localization social services existes Gowalla, Loopt, BrightKit , …etc, I didn’t tried them all, but I’ll certainly do.
Twitter also provide based localization services, associating Tweets to places became a common thing. facebook will also certainly do …


Bookmark and Share

San Francisco : The 3rd f8 conference ! A new web era announced !

This week was held the 3rd f8 conference in San Francisco ! Facebook team talked about many of those features they announced since their last conferences. I was thinking when following online keynotes & sessions about – my thoughts by writing this article.

So first , let’s talk about these new concepts of social experiences, social graph & social plugins or how the social networking are evolving using OAUTH 2.0 !These new concepts, as explained by Zuck during the keynote session represents  new tendencies which will transform the web seen actually as a group of many social graphs into an open graph where pages will become nodes and connections will be established through what they call The users web experiences !

This can be performed by adding a new social web concept : The social objects , The main idea behind this concept is allowing facebook users expressing relationships with arbitrary objects.
The pages you visited , the artices, movies & sounds you interract with represent theses social objects … so try to imagine all the new social connections established Transforming all these social graphs into what they called an “Open Graph” .

Let’s now dive deeper into these new concepts, Zuck’s team talked about social plugins provided for developer to make their pages more social transforming them into social objects !  These social plugins can be intergrated without writing any line of code, without downloading any SDK or documentation ! it can be easly integrated just by adding one or two html line code into your pages and your web site will be socialy enable. now let’s talk about these plugins!

The one they focused on during this 3rd conference was the famous “like button“ , you’d probably already found it on several pages, just under articles, movies and other kind of information shared on the web. It’s a new way of building your profile juste through your personal web experience. I invit you to hear more about this by following zuck’s talk:

In addition to this magic “like button” other social plugins are also provided. Activity stream and recommendation plugin can also be found everywhere on the web. Bringing your social network whereever you are!

What about sharing experiences, let’s explain it through an exemple… for exemple if you’re surfing on CNN’s web site, The activity stream and recommendation plugin will provide you a list of performed activities related to your social network members experience, on this web site.

The last plugin they talked about was “The social bar”. It includes all the plugins described above adding to the facebook real time chat.

Let’s talk now about how to integrate these plugins. nothing hard, they had introduce a new protocol, which was obviously called the Open Graph protocol (OGP). they introduced it as meta tags including meta data describing the informations shared.let’s Now analyse these lines of code :

<html xmlns:og=”http://opengraphprotocol.org/schema/”>
<head>
<title>Avatar (2010)</title>
<meta property=”og:title” content=”Avatar” />
<meta property=”og:type” content=”movie” />
<meta property=”og:url” content=”http://www.avatar-lefilm.com/” />
<meta property=”og:image” content=”http://blog.lefigaro.fr/bd/avatar_james_cameron_infos_3.jpg” />

</head>

</html>

it describes open graph <meta> tag provided for a movie just for fixing the kind of information aimed by any user. when you performed a social activity (like button or comment) on this web page, facebook will be able to classify your social activity… this can give a meaningful or a semantic
representation for what you instantly experienced on the web.
Facebook can also get updates from this socialized web sites bringing a lot of social administration & visualisation tool to any developer using these social plugins.

Final Thoughts …
I advice you to follow Mark Kinsey conference about the OG protocol & social plugins.
Alex Himel had also presented new administration and visualization tools really interesting :p .
Mike Vernal also talked during the breakout session about the Open graph API.
These new concepts will probably shape the way information can moves through users web experiences. the question is : are we entering a new real time web area ? just wait & see :p


Bookmark and Share