Subject: | 401 unauthorized for no apparent reason |
going off of the code here http://search.cpan.org/~jessestay/Catalyst-Authentication-
Credential-Twitter-0.01001/lib/Catalyst/Authentication/Credential/Twitter.pm and setting
up the config parameters properly, I get this error: [error] Caught exception in
MyApp::Controller::Users->twitter_callback "GET http://twitter.com/oauth/access_token
failed: 401 Unauthorized at /opt/local/lib/perl5/site_perl/5.8.9/Net/Twitter/Role/OAuth.pm
line 134."
No apparent reason. No reasonable way to debug, as tests in t/ are mostly for pod coverage.
Also, I had to add the Session::PerUser plugin to my plugin list in order to get this Credential
working, even though it's supposed to import the module on its own.
Here is my source listing for the pertinent actions and config:
<twitter>
<credential>
class Twitter
</credential>
consumer_key (hidden)
consumer_secret (hidden)
callback_url http://localhost:3000/login/tw_callback
</twitter>
sub twitter : Chained('login_base') PathPart('twitter') Args(0) {
my ( $self, $c ) = @_;
my $realm = $c->get_auth_realm('twitter');
$c->res->redirect( $realm->credential->authenticate_twitter_url($c) );
}
sub twitter_callback : Chained('login_base') PathPart('tw_callback') Args(0) {
my ( $self, $c ) = @_;
my $redirect_to = $c->stash->{'redirect_to'} || $c->uri_for('/');
if ( my $user = $c->authenticate( undef, 'twitter' ) ) {
$c->model('Database::User')->find_or_create(
{
credential_identifier => $c->user->session_uid,
credential_source => 'twitter',
}
);
$c->res->redirect($redirect_to);
}
else {
$c->error("Twitter auth failed!");
$c->detach;
}
}