Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_token_p seems to always return undef on callback when not called from controller #76

Open
rawleyfowler opened this issue Nov 20, 2023 · 0 comments

Comments

@rawleyfowler
Copy link

rawleyfowler commented Nov 20, 2023

I'm implementing OAuth in a pretty large code-base, i've passed the OAuth2 object down from the controller into a service layer object, which ultimately should be making the call too get_token_p however, the parameter passed to the ->then(...) callback seems to ALWAYS be undef, and at the speed of the error I'm almost 100% sure it doesn't make a call at all. I haven't had this issue with seemingly identical code that lives in the Mojolicious::Controller,

Custom service level code

sub execute {
   my $self = shift;
   my $args = {
      scope        => $self->scope, # 'user email'
      redirect_uri => $self->redirect_uri # 'http://localhost:3000/login/github'
   };

   return $self->oauth->get_token_p( github => $args )->then(
      sub {
         my $pr = shift;

         use DDP;

         p $pr;
         p $self->oauth->providers;

         return $pr->{access_token};
      });
}

First print:

undef

Second print (redacted of course):

    github         {
        authorize_url   "https://github.com/login/oauth/authorize",
        key             "XXX" (dualvar: 6),
        secret          "XXX",
        token_url       "https://github.com/login/oauth/access_token"
    },

Controller code

sub github {
    my $self = shift;

    Project::Service::OAuth2::Github->new(oauth => $self->oauth2)->execute->then(sub { ... });
}
@rawleyfowler rawleyfowler changed the title get_token_p seems to always return undef on callback get_token_p seems to always return undef on callback when not called from controller Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant