Skip to content

oauth2_server_db.pl question #30

Closed
@danjboyd

Description

I was noticing that the user_id was getting dropped from the JWT/access token after I refreshed with a refresh token.

Looking at the sample code, under

my $verify_access_token_sub = sub {
  my ( %args ) = @_;

  my ( $c,$access_token,$scopes_ref,$is_refresh_token )
        = @args{qw/ mojo_controller access_token scopes is_refresh_token /};


  my $rt = $c->db->get_collection( 'refresh_tokens' )->find_one({
    refresh_token => $access_token
  });

  if ( $is_refresh_token && $rt ) {

    if ( $scopes_ref ) {
      foreach my $scope ( @{ $scopes_ref // [] } ) {
        if ( ! exists( $rt->{scope}{$scope} ) or ! $rt->{scope}{$scope} ) {
          $c->app->log->debug(
            "OAuth2::Server: Refresh token does not have scope ($scope)"
          );
          return ( 0,'invalid_grant' );
        }
      }
    }

    return $rt;     # <-- just returning a scalar here

if it's a refresh token, we ultimately just return $rt.

But, that method is ultimately called from Mojolicious::Plugin::OAuth2::Server.pm in the _verify_credentials sub:

if ( $grant_type eq 'refresh token' ) {
  ( $client,$error,$scope,$user_id ) = $Grant->verify_token_and_scope(   <-- this calls verify_access_token_sub
                                                                             and is expecting 4 return variables
                                                                             including $user_id
    refresh_token =>   $refresh_token,
    auth_header =>     $self->req->headers->header( 'Authorization' ),
    mojo_controller => $self,
  );
  $old_refresh_token = $refresh_token;
...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions