Skip to content

Conversation

@bkotrys
Copy link
Contributor

@bkotrys bkotrys commented Dec 6, 2019

Changes

This PR adds possibility to provide additional options to renewTokens method. This options (especially scope option) are necessary in situation when we add custom scope to context.accessToken and would like to renew tokens. Without providing proper scope (openid) after calling renewTokens method we got following error:
Token did not refresh correctly. Access or ID token not provided.

Example rule - add custom scope to accessToken

function (user, context, callback) {
  var permissions = [
    'permission1',
    'permission2'
  ];
  
  const requestedScope = (
    (context.request.query && context.request.query.scope) || 
    (context.request.body && context.request.body.scope)
  );

  if(requestedScope) {
    const scopes = requestedScope.split(' ');
    
    if(scopes.indexOf('openid') !== -1) {
      permissions.push('openid');
    }
    
    if(scopes.indexOf('profile') !== -1) {
      permissions.push('profile');
    }
    
    if(scopes.indexOf('email') !== -1) {
      permissions.push('email');
    }
    
    if(scopes.indexOf('offline_access') !== -1) {
      permissions.push('offline_access');
    }
  }

  context.accessToken.scope = (context.accessToken.scope || []).concat(permissions);
  callback(null, user, context);
}

References

Relates to:

May be somehow related to these issues:

**

Testing

  • This change adds test coverage

  • This change has been tested on the latest version of PHP

Checklist

@bkotrys bkotrys requested a review from a team December 6, 2019 09:42
@joshcanhelp joshcanhelp requested review from joshcanhelp and removed request for a team December 6, 2019 20:57
Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkotrys - We appreciate the very detailed report and concise PR here! I'm happy to merge this in but we probably want to re-think the documentation provided (see comment). We're gearing up for the last (planned) release for this major and happy to get this PR in before that goes out.

src/Auth0.php Outdated
Comment on lines 598 to 600
* - options.grant_type Grant type to use; required.
* - options.client_id Application Client ID; required.
* - options.client_secret Application Client Secret; required if token endpoint requires authentication.
Copy link
Contributor

@joshcanhelp joshcanhelp Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would definitely leave these out since the first must be refresh_token (and is added automatically) and the others are added automatically with whatever the Auth0 object was initiated with. The audience is ignored in the refresh case (that info is part of the refresh token record). And, in the case of scope, that's ignored in most cases as well (not yours, of course).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshcanhelp updated, please let me know if this satisfied you.

@joshcanhelp joshcanhelp added this to the 5.7.0 milestone Dec 9, 2019
@joshcanhelp
Copy link
Contributor

❯ composer test
> SHELL_INTERACTIVE=1 "vendor/bin/phpunit" --coverage-text
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.29 with Xdebug 2.6.1
Configuration: /Users/josh-cunningham/Sites/php-auth0/auth0/phpunit.xml.dist

...S...........................................................  63 / 253 ( 24%)
............................................................... 126 / 253 ( 49%)
............................................................... 189 / 253 ( 74%)
............................................................... 252 / 253 ( 99%)
.                                                               253 / 253 (100%)

Time: 26.51 seconds, Memory: 18.00MB

There was 1 skipped test:

1) Auth0\Tests\API\Authentication\DeprecatedTest::testAuthorizeWithRO
New applications do not provide this grant.

/Users/josh-cunningham/Sites/php-auth0/auth0/tests/API/Authentication/DeprecatedTest.php:12

OK, but incomplete, skipped, or risky tests!
Tests: 253, Assertions: 929, Skipped: 1.

❯ snyk test

Testing /Users/josh-cunningham/Sites/php-auth0/auth0...

Organization:      auth0-sdks
Package manager:   composer
Target file:       composer.lock
Open source:       no
Project path:      /Users/josh-cunningham/Sites/php-auth0/auth0
Licenses:          enabled

✓ Tested 8 dependencies for known issues, no vulnerable paths found.

Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkotrys - Thank you for the update here! I added a test for the custom options so I think this is good to go. We'll get this released today or tomorrow 👍

@joshcanhelp joshcanhelp merged commit 7a7f098 into auth0:master Dec 9, 2019
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants