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

Add /userinfo fallback during login #423

Merged
merged 2 commits into from
Apr 13, 2018
Merged

Add /userinfo fallback during login #423

merged 2 commits into from
Apr 13, 2018

Conversation

joshcanhelp
Copy link
Contributor

@joshcanhelp joshcanhelp commented Mar 29, 2018

Some customers are having trouble with the upgrade process in 3.5.2 while others made make changes to their account disabling management API access. This fallback allows user data to be pulled for logging-in users. Also adds requested scopes for auth code login to make this possible and updates the error manager class to handle a common error case.

@joshcanhelp joshcanhelp added this to the v3-Next milestone Mar 29, 2018
@joshcanhelp joshcanhelp self-assigned this Mar 29, 2018
@@ -19,9 +19,12 @@ public static function insert_auth0_error( $section, $error ) {
} elseif ( $error instanceof Exception ) {
$code = $error->getCode();
$message = $error->getMessage();
} elseif ( is_array( $error ) && ! empty( $error['response'] ) ) {
Copy link
Contributor Author

@joshcanhelp joshcanhelp Mar 29, 2018

Choose a reason for hiding this comment

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

Typical response from wp_remote_post() and wp_remote_get()

@joshcanhelp
Copy link
Contributor Author

Addresses #401

protected $signup_mode = false;
protected $_id_token_scopes = 'openid email email_verified name nickname picture';
Copy link
Member

Choose a reason for hiding this comment

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

why id_token_scopes btw and not just scopes?

$userinfo_resp_body = wp_remote_retrieve_body( $userinfo_resp );

// Management API call failed
// Management API call failed, fallback to userinfo
Copy link
Member

Choose a reason for hiding this comment

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

So why does Management API fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something we should have had in 3.5.0. It will fail if the Client/Application is not authorized on the Management API or if Client Grant has not been turned on. Has been a common support theme and wanted to get it in there for anyone else upgrading.

@@ -19,9 +19,12 @@ public static function insert_auth0_error( $section, $error ) {
} elseif ( $error instanceof Exception ) {
$code = $error->getCode();
$message = $error->getMessage();
} elseif ( is_array( $error ) && ! empty( $error['response'] ) ) {
$code = ! empty( $error['response']['code'] ) ? $error['response']['code'] : 'N/A';
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of N/A use something like a0_unknown_code or if you received a "plain text response" then use that as description and use some code like a0_plaintext_error

@@ -19,9 +19,12 @@ public static function insert_auth0_error( $section, $error ) {
} elseif ( $error instanceof Exception ) {
$code = $error->getCode();
$message = $error->getMessage();
} elseif ( is_array( $error ) && ! empty( $error['response'] ) ) {
$code = ! empty( $error['response']['code'] ) ? $error['response']['code'] : 'N/A';
$message = ! empty( $error['response']['message'] ) ? $error['response']['message'] : 'N/A';
Copy link
Contributor

Choose a reason for hiding this comment

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

this one is fine, it makes sense.

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

scope issues

protected $signup_mode = false;
protected $_scopes = 'openid email email_verified name nickname picture';
Copy link
Contributor

Choose a reason for hiding this comment

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

email_verified included in email

protected $signup_mode = false;
protected $_id_token_scopes = 'openid email email_verified name nickname picture';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same scope comment

@@ -245,30 +244,29 @@ public function redirect_login() {

// Attempt to authenticate with the Management API
$client_credentials_token = WP_Auth0_Api_Client::get_client_token();
$userinfo_resp = null;
$userinfo_resp_code = $userinfo_resp_body = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this 2 = assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Equivalent to:

$userinfo_resp_code = null;
$userinfo_resp_body = null;

@joshcanhelp joshcanhelp force-pushed the add-userinfo-fallback branch 4 times, most recently from 9850da0 to c721384 Compare April 10, 2018 22:34
Some customers are having trouble with the upgrade process in 3.5.2 while others made make changes to their account disabling management API access. This fallback allows user data to be pulled for logging-in users. Also adds requested scopes for auth code login to make this possible.
@joshcanhelp joshcanhelp merged commit 08982f8 into dev Apr 13, 2018
@joshcanhelp joshcanhelp deleted the add-userinfo-fallback branch April 13, 2018 14:09
@joshcanhelp joshcanhelp mentioned this pull request Jun 5, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 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.

None yet

3 participants