CatalystX-OAuth2-Provider

 view release on metacpan or  search on metacpan

lib/CatalystX/OAuth2/Provider/Controller/OAuth.pm  view on Meta::CPAN

                   error_description => 'Invalid grant type');
      $ctx->res->body( JSON::XS->new->pretty(1)->encode( \%data ) );
}

sub handle_grant_type : Private {
    my ( $self, $ctx, $grant_type ) = @_;
}


=head2 authorize
    Authorize endpoint
=cut
sub authorize
    :Chained('logged_in_required')
    :PathPart('authorize') #Configurable?
    :Args(0)
{
    my ( $self, $ctx ) = @_;

    if ( $ctx->req->method eq 'GET' ) {
       $ctx->stash( authorize_endpoint => $ctx->uri_for_action($ctx->action) );
       $ctx->stash( template => $self->{authorize_form}->{template}
                                 || 'oauth/authorize.tt' );
    }

    if ( $ctx->req->method eq 'POST' ) {

        my $uri  = $ctx->uri_for( $ctx->req->param("redirect_uri"),
                                      { code         => $ctx->sessionid,
                                        redirect_uri => $ctx->req->param("redirect_uri"),
                                      } );

t/lib/TestApp/root/oauth/authorize.tt  view on Meta::CPAN

<form method="POST" action="[% authorize_endpoint %]">
Do you wish to allow the service named <b>'[% client.client_name %]'</b> to access this application on your behalf?
<input type="submit" value="Yes" name="authorize" />
<input type="submit" value="No" name="authorize" />


<input type="hidden" name="client_id" id="client_id" value="[% client.client_id %]" />
<input type="hidden" name="redirect_uri" id="redirect_uri" value="[% c.req.params.redirect_uri %]" />
<input type="hidden" name="response_type" id="response_type" value="code" />


t/live-test.t  view on Meta::CPAN


# make sure testapp works
use ok 'TestApp';

# a live test against TestApp, the test application
use Test::WWW::Mechanize::Catalyst 'TestApp';
my $mech = Test::WWW::Mechanize::Catalyst->new;
$mech->get_ok('http://localhost/', 'get main page');
$mech->content_like(qr/it works/i, 'see if it has our text');

subtest 'simple test for endpoint', sub {
    my $client_id = "36d24a484e8782decbf82a46459220a10518239e";
    $mech->get_ok("http://localhost/oauth/token?client_id=$client_id", 'a token endpoint');
    $mech->get("http://localhost/oauth/authorize?client_id=$client_id", 'an authorize endpoint');
    is( $mech->status, 200, "Login required" );
};

subtest 'test for protected resource', sub {
     my $mac = "MAC token=h480djs93hd8,";
     $mac .= "timestamp=137131200,";
     $mac .= "nonce=dj83hs9s,";
     $mac .= "signature=U2FsdGVkX1/3UV6R0SnZvqNDtP7evqzSY12FQoAhemnSJhLDhXpwb2sjPeeBJH14cb3fD1kdREMVyQGl8UlwSg==";
     $mech->add_header( Authorization => $mac );
     my $test_api = 'http://localhost/my/test';



( run in 0.244 second using v1.01-cache-2.11-cpan-27979f6cc8f )