Skip to content

Commit

Permalink
ClientCredentials grant handler now works as expected when client_use…
Browse files Browse the repository at this point in the history
…r_id == 0
  • Loading branch information
lyokato committed May 17, 2011
1 parent 355864b commit 6057220
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension OAuth::Lite2.

0.01_11 Tue May 17 19:43:00 2011
- client credentials grant handler now works as expected when client_user_id == 0

0.01_10 Thu Mar 17 13:28:00 2011
- removed Context. Now, DataHandler has request object, and you pick it up
by DataHandler::request.
Expand Down
2 changes: 1 addition & 1 deletion lib/OAuth/Lite2.pm
Expand Up @@ -3,7 +3,7 @@ package OAuth::Lite2;
use strict;
use warnings;

our $VERSION = '0.01_10';
our $VERSION = '0.01_11';

1;
__END__
Expand Down
4 changes: 2 additions & 2 deletions lib/OAuth/Lite2/Server/GrantHandler/ClientCredentials.pm
Expand Up @@ -15,8 +15,8 @@ sub handle_request {
my $client_id = $req->param("client_id");
my $client_secret = $req->param("client_secret");

my $user_id = $dh->get_client_user_id($client_id, $client_secret)
or OAuth::Lite2::Server::Error::InvalidClient->throw;
my $user_id = $dh->get_client_user_id($client_id, $client_secret);
OAuth::Lite2::Server::Error::InvalidClient->throw unless defined $user_id;

my $scope = $req->param("scope");

Expand Down
25 changes: 22 additions & 3 deletions t/030_server/token_endpoint/client_credentials.t
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use lib 't/lib';
use Test::More tests => 6;
use Test::More tests => 11;

use Plack::Request;
use Try::Tiny;
Expand All @@ -11,16 +11,23 @@ use OAuth::Lite2::Server::GrantHandler::ClientCredentials;
use OAuth::Lite2::Util qw(build_content);

TestDataHandler->clear;
TestDataHandler->add_client(id => q{foo}, secret => q{bar}, user_id => 1);
TestDataHandler->add_client(id => q{foo}, secret => q{bar}, user_id => 1);
TestDataHandler->add_client(id => q{buz}, secret => q{hoge}, user_id => 0);

my $dh = TestDataHandler->new;
my $auth_info = $dh->create_or_update_auth_info(
client_id => q{foo},
user_id => q{1},
scope => q{email},
);
my $auth_info2 = $dh->create_or_update_auth_info(
client_id => q{buz},
user_id => q{0},
scope => q{email},
);

is($auth_info->refresh_token, "refresh_token_0");
is($auth_info2->refresh_token, "refresh_token_1");

my $action = OAuth::Lite2::Server::GrantHandler::ClientCredentials->new;

Expand Down Expand Up @@ -90,9 +97,21 @@ sub test_error {
}, {
token => q{access_token_0},
expires_in => q{3600},
refresh_token => q{refresh_token_1},
refresh_token => q{refresh_token_2},
});

# work as expected when user_id is 1
&test_success({
client_id => q{buz},
client_secret => q{hoge},
}, {
token => q{access_token_1},
expires_in => q{3600},
refresh_token => q{refresh_token_3},
});

&test_error({
client_id => q{unknown},
client_secret => q{bar},
}, q/invalid_client/);

0 comments on commit 6057220

Please sign in to comment.