[Catalyst] Catalyst::Authentication::Credential::OAuth
Hernan Lopes
hernanlopes at gmail.com
Tue Nov 23 23:27:49 GMT 2010
To integrate facebook login onto your site,
Have you tried Catalyst::Authentication::Credential::FBConnect ?
It works and lets you access users facebook id from $c->user->session_uid as
documented
1. You need to register under http://developers.facebook.com and register a
new application. You must include the exact address you will use on the
machine for it to work ie. "http://localhost:3000/"
2. you need to configure include these onto your myapp.conf
<Plugin::Authentication>
default_realm facebook
<realms>
<facebook>
<credential>
class FBConnect
api_key my_app_key
secret my_app_secret
app_name my_app_name
</credential>
</facebook>
</realms>
</Plugin::Authentication>
3. you need a piece of javascript from facebook to create login button
(replace with your appId/fb_app_id as below):
sub login_facebook : Path('/loginfacebook') : Args(0) {
my ( $self, $c ) =3D @_;
my $fb_app_id =3D '9999999999999999';
$c->stash( template =3D> \<<FBLOGIN
<p><fb:login-button autologoutlink=3D"true"></fb:login-button></p>
<p><fb:like></fb:like></p>
<div id=3D"fb-root"></div>
<script>
window.fbAsyncInit =3D function() {
FB.init({appId: '$fb_app_id', status: true, cookie: true,
xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location=3D"/fblogin"; //redirects user to our facebook
login so we can validate him and get his user id.
} else {
// The user has logged out, and the cookie has been cleared
window.location=3D"/";
}
});
};
(function() {
var e =3D document.createElement('script');
e.type =3D 'text/javascript';
e.src =3D document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async =3D true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
FBLOGIN
);
}
4. then , i created an action /fblogin to register facebook credentials
internally when user logs in (see in the js)
sub fbauthenticate :Path('/fblogin') :Args(0) {
my ($self, $c) =3D @_;
if ($c->authenticate()) {
$c->log->debug($c->user->session_uid);
$c->log->debug($c->user->session_key);
$c->log->debug($c->user->session_expires);
}
$c->res->redirect('/');
}
So remember, register at the http://developer.facebook.com with the same url
your application will use, include ports if its not 80
--Hernan
On Tue, Nov 23, 2010 at 8:32 PM, Blaine Everingham <
grandmasterblaine at hotmail.com> wrote:
> Hi,
>
> I was wondering if anyone has a simple example of using OAuth with facebo=
ok
> to allow user login, to your software.
>
> I keep getting the error "oauth_parameters_absent:scope", but
> Catalyst::Authentication::Credential::OAuth document does not outline whe=
re
> you are supposed to enter this.
>
> Thanks,
> Blaine
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101123/215c2=
ceb/attachment.htm
More information about the Catalyst
mailing list