Skip to content

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

Open
@rawleyfowler

Description

@rawleyfowler

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 { ... });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions