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

Authorization Extension, groups, roles not showing up #701

Closed
jigsawsoul opened this issue Jul 21, 2019 · 1 comment
Closed

Authorization Extension, groups, roles not showing up #701

jigsawsoul opened this issue Jul 21, 2019 · 1 comment
Milestone

Comments

@jigsawsoul
Copy link

Hi,

I am using the Authorization Extension - although seem to be having trouble receiving data regarding the user's groups, roles and permissions.

The extension added rule automatically to enable this information to be passed back with the user information. I am trying to access this information within the auth0_user_login hook but I have yet to have any luck.

Some context of what I am trying to achieve may help. I have a large network of over 30 WordPress sites, all with the same internal users. I which to have one auth0 application for all sites and then match the roles in the extension to the default WordPress rules. Groups will be used to match the domain. e.g. if a user is assigned to group:github.com they will be able to access that site, if not they will be rejected from being able to log in.

Some direction would really help of how to get this additional information to show up in WordPress.

Thanks in advance.

@joshcanhelp
Copy link
Contributor

@jigsawsoul - Happy to help and apologies for the delay!

The WP plugin does not currently have code that will sync up roles so using the hook you mentioned is the right way to go.

A lot of this guidance depends on how your plugin is setup but, with a default configuration, you'll want the Rule that the extension publishes to persist the data you're using (permissions, roles, and/or groups) in the metadata so WP can retrieve it on login. Your configuration screen should look like this (make sure you Publish Rule again if you make changes):

Screen Shot 2019-07-29 at 10 27 38 AM

With that in place, you can now access this data from the app_metadata property in that hook:

// WARNING: This code will break the login process!
function namespaced_action_auth0_user_login( $user_id, $userinfo ) {
	// TODO: Remove debugging
	echo '<pre>' . print_r( $userinfo->app_metadata->authorization, TRUE ) . '</pre>'; die();;
}
add_filter( 'auth0_user_login', 'namespaced_action_auth0_user_login', 100, 2 );

You should get:

stdClass Object
(
    [groups] => Array
        (
        )

    [roles] => Array
        (
            [0] => Your Role
        )

    [permissions] => Array
        (
            [0] => action:entity
        )

)

What you do with that information is up to you but that's how you access it. Hopefully that's helpful but please reply back if you have any additional questions!

@joshcanhelp joshcanhelp added this to the 4.0.0 milestone Feb 7, 2020
@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

No branches or pull requests

2 participants