Skip to content

Commit

Permalink
return client and username from verify_user_password
Browse files Browse the repository at this point in the history
as this plays better with Mojolicious::Plugin::OAuth2::Server and
is also more useful information
  • Loading branch information
leejo committed Apr 17, 2016
1 parent 71f3388 commit 0cc55db
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Revision history for Net-OAuth2-AuthorizationServer

0.05 2016-04-17
0.06 2016-04-17
- Add Net::OAuth2::AuthorizationServer::PasswordGrant
- Add Net::OAuth2::AuthorizationServer::Manual

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Authorization Server

# VERSION

0.05
0.06

# SYNOPSIS

Expand Down
4 changes: 2 additions & 2 deletions lib/Net/OAuth2/AuthorizationServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Authorization Server
=head1 VERSION
0.05
0.06
=head1 SYNOPSIS
Expand Down Expand Up @@ -43,7 +43,7 @@ use Types::Standard qw/ :all /;
use Net::OAuth2::AuthorizationServer::AuthorizationCodeGrant;
use Net::OAuth2::AuthorizationServer::PasswordGrant;

our $VERSION = '0.05';
our $VERSION = '0.06';

=head1 GRANT TYPES
Expand Down
10 changes: 5 additions & 5 deletions lib/Net/OAuth2/AuthorizationServer/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ client_id, client_secret, username, password, an optional reference to a list of
the scopes.

The callback should verify client details and username + password and return a
a list with 4 elements. The first element should be a boolean to signal if the
client details + username is valid. The second element should be the error message
in the case of bad credentials. The third element should be an array reference of
the required scopes.
a list with 4 elements. The first element should be the client id if the client
details + username is valid. The second element should be the error message in
the case of bad credentials. The third element should be an array reference of
the required scopes. The fourth should be the username.

my $verify_user_password_sub = sub {
my ( $self, %args ) = @_;
Expand All @@ -483,7 +483,7 @@ the required scopes.
return ( 0, 'invalid_grant' );
}
else {
return ( 1, undef, $scopes );
return ( $client_id, undef, $scopes, $username );
}

};
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/OAuth2/AuthorizationServer/PasswordGrant.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ sub _verify_user_password {
return ( 0, 'invalid_grant' );
}
else {
return ( 1, undef, $scopes );
return ( $client_id, undef, $scopes, $username );
}

}
Expand Down
2 changes: 1 addition & 1 deletion t/net/oauth2/authorizationserver/passwordgrant.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sub token_format_tests {
'sleep'
],
'type' => $type,
'user_id' => 1
'user_id' => 'test_user',
},
'auth code decodes correctly',
);
Expand Down
19 changes: 11 additions & 8 deletions t/net/oauth2/authorizationserver/passwordgrant_tests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ sub run_tests {
scopes => [ qw/ eat sleep / ],
);

my ( $client,$vac_error,$scopes ) = $Grant->verify_user_password( %valid_user_password );
my ( $og_client,$vac_error,$scopes,$user_id )
= $Grant->verify_user_password( %valid_user_password );

ok( $client,'->verify_user_password, correct args' );
ok( $og_client,'->verify_user_password, correct args' );
ok( ! $vac_error,'has no error' );
cmp_deeply( $scopes,[ qw/ eat sleep / ],'has scopes' );

Expand All @@ -65,7 +66,7 @@ sub run_tests {
[ { username => 'i_do_not_exist' },'invalid_grant','bad username' ],
[ { password => 'bad_password' },'invalid_grant','bad password' ],
) {
( $client,$vac_error,$scopes ) = $Grant->verify_user_password(
my ( $client,$vac_error,$scopes ) = $Grant->verify_user_password(
%valid_user_password,%{ $t->[0] },
);

Expand All @@ -74,30 +75,32 @@ sub run_tests {
ok( ! $scopes,'has no scopes' );
}

my $client = $og_client;

note( "store_access_token" );

ok( my $access_token = $Grant->token(
client_id => 'test_client',
client_id => $client,
scopes => [ qw/ eat sleep / ],
type => 'access',
user_id => 1,
user_id => $user_id,
),'->token (access token)' );

$args->{token_format_tests}->( $access_token,'access' )
if $args->{token_format_tests};

ok( my $refresh_token = $Grant->token(
client_id => 'test_client',
client_id => $client,
scopes => [ qw/ eat sleep / ],
type => 'refresh',
user_id => 1,
user_id => $user_id,
),'->token (refresh token)' );

$args->{token_format_tests}->( $refresh_token,'refresh' )
if $args->{token_format_tests};

ok( $Grant->store_access_token(
client_id => 'test_client',
client_id => $client,
access_token => $access_token,
refresh_token => $refresh_token,
scopes => [ qw/ eat sleep / ],
Expand Down

0 comments on commit 0cc55db

Please sign in to comment.