| 1 | package CatalystX::OAuth2::Provider::TraitFor::Controller::OAuth::AuthorizationCode; | ||
| 2 | |||
| 3 | use MooseX::MethodAttributes::Role; | ||
| 4 | use OAuth::Lite::Token; | ||
| 5 | use namespace::autoclean; | ||
| 6 | |||
| 7 | requires qw/ | ||
| 8 | handle_grant_type | ||
| 9 | /; | ||
| 10 | |||
| 11 | around 'handle_grant_type' => sub { | ||
| 12 | my ( $orig, $self, $ctx, $grant_type ) = @_; | ||
| 13 | |||
| 14 | if (! $ctx->session->{token}) { | ||
| 15 | my $t = OAuth::Lite::Token->new_random; | ||
| 16 | $ctx->session->{token} = $t->token; | ||
| 17 | } | ||
| 18 | |||
| 19 | if ( $grant_type && ( $grant_type eq 'authorization_code' ) ) { | ||
| 20 | my %data = ( access_token => $ctx->session->{token}, | ||
| 21 | expires_in => 3600, #TODO: Make access_token expires | ||
| 22 | scope => undef, #TODO: Support scope | ||
| 23 | refresh_token => $ctx->session->{token} ); | ||
| 24 | $ctx->res->body( JSON::XS->new->pretty(1)->encode( \%data ) ); | ||
| 25 | $ctx->detach(); | ||
| 26 | } | ||
| 27 | |||
| 28 | }; | ||
| 29 | |||
| 30 | =pod | ||
| 31 | =cut | ||
| 32 | |||
| 33 | 1; |