Skip to content

Commit

Permalink
Released version 1.51
Browse files Browse the repository at this point in the history
    - Fix get_token() need to return the whole data structure to the callback
      and not just $token.
  • Loading branch information
Jan Henning Thorsen committed Mar 18, 2015
1 parent 049f245 commit db86b96
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,3 +1,7 @@
1.51 2015-03-18 17:38:19
- Fix get_token() need to return the whole data structure to the callback
and not just $token.

1.5 2015-03-02 08:31:47
- Able to mock interface for easy testing

Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -2,7 +2,7 @@
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Mojolicious::Plugin::OAuth2',
AUTHOR => 'Jan Henning Thorsen <jhthorsen@cpan.org>',
AUTHOR => 'Marcus Ramberg <marcus@nordaaker.com>',
LICENSE => 'artistic_2',
ABSTRACT_FROM => 'lib/Mojolicious/Plugin/OAuth2.pm',
VERSION_FROM => 'lib/Mojolicious/Plugin/OAuth2.pm',
Expand Down
31 changes: 15 additions & 16 deletions README
Expand Up @@ -27,7 +27,7 @@ SYNOPSIS

plugin "OAuth2" => {
facebook => {
key => "some-public-app-id",
key => "some-public-app-id",
secret => $ENV{OAUTH2_FACEBOOK_SECRET},
},
};
Expand All @@ -37,13 +37,13 @@ SYNOPSIS
$c->delay(
sub {
my $delay = shift;
my $args = { redirect_uri => $c->url_for('connect')->userinfo(undef)->to_abs };
$c->oauth2->get_token(facebook => $args, $delay->begin)
my $args = {redirect_uri => $c->url_for('connect')->userinfo(undef)->to_abs};
$c->oauth2->get_token(facebook => $args, $delay->begin);
},
sub {
my($delay, $err, $token) = @_;
return $c->render("connect", error => $err) unless $token;
return $c->session(token => $token)->redirect_to('profile');
my ($delay, $err, $data) = @_;
return $c->render("connect", error => $err) unless $data->{access_token};
return $c->session(token => $c->redirect_to('profile'));
},
);
};
Expand All @@ -62,10 +62,10 @@ SYNOPSIS

plugin "OAuth2" => {
custom_provider => {
key => "APP_ID",
secret => "SECRET_KEY",
key => "APP_ID",
secret => "SECRET_KEY",
authorize_url => "https://provider.example.com/auth",
token_url => "https://provider.example.com/token",
token_url => "https://provider.example.com/token",
},
};

Expand Down Expand Up @@ -130,9 +130,9 @@ SYNOPSIS

* POST /mocked/oauth/token

This route is will return an "access_token" which will be the $token
variable in your "oauth.get_token" callback. The default is
"fake_token", but it can be configured:
This route is will return a "access_token" which is available in
your "oauth2.get_token" callback. The default is "fake_token", but
it can be configured:

$c->app->oauth2->providers->{mocked}{return_token} = "...";

Expand Down Expand Up @@ -185,7 +185,7 @@ HELPERS
$c = $c->oauth2->get_token(
$provider_name => \%args,
sub {
my ($c, $err, $token) = @_;
my ($c, $err, $data) = @_;
}
);

Expand All @@ -198,9 +198,8 @@ HELPERS
provider's page or not.

2. The OAuth2 provider will redirect the user back to your site after
clicking the "Connect" or "Reject" button. $token will then contain
a string on "Connect" and a false value on "Reject". You can
investigate $tx if $token holds a false value.
clicking the "Connect" or "Reject" button. $data will then contain a
key "access_token" on "Connect" and a false value on "Reject".

Will redirect to the provider to allow for authorization, then fetch the
token. The token gets provided as a parameter to the callback function.
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/OAuth2.pm
Expand Up @@ -6,7 +6,7 @@ use Mojo::Util 'deprecated';
use Carp 'croak';
use strict;

our $VERSION = '1.5';
our $VERSION = '1.51';

has providers => sub {
return {
Expand Down Expand Up @@ -54,7 +54,8 @@ sub register {
$self->providers($providers);

unless ($self->{fix_get_token} = $config->{fix_get_token}) {
deprecated "\$c->oauth2->get_token(...) has changed api!";
deprecated
"\$c->oauth2->get_token(...) has changed api! Please set 'fix_get_token' in the config arguments to move forward. Sorry for the inconvenience.";
}

if ($providers->{mocked}{key}) {
Expand Down

0 comments on commit db86b96

Please sign in to comment.