CatalystX-OAuth2-Provider

 view release on metacpan or  search on metacpan

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

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                   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

1
2
3
4
5
6
7
8
9
<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

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# make sure testapp works
use ok 'TestApp';
 
# a live test against TestApp, the test application
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.527 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )