• through your, plugin WordPress acts as OAuth server and takes user data from the WordPress to 3rd party app (rocket chat). now I want to only allow certain user roles to do login in my 3rd party app. so is it possible that only Editor or only XYZ (custom user role). this should be only applied when someone tries to do login from 3rd party app (rocket chat user tries login by using WordPress as Oauth server) other than this WordPress normal login should allow every user to do login, I hope you understand my question. I’m ready to modify your plugin as per your guidance just tell in which file, in which line is should change and or add your new code. I’m ready to pay if you can help me. thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Justin Greer

    (@justingreerbbi)

    Hi,

    It sounds like you are wanting to limit SSO flow based on the user roles in WordPress. If this correct?

    Thread Starter Gigabyteservice

    (@gigabyteservice)

    Yes, and than you for your response

    Thread Starter Gigabyteservice

    (@gigabyteservice)

    @justingreerbbi can you please help to use role based login in client side app?

    I only want to allow xyz user role (it’s wordpress user role ) to be able to do login, where the wordpress act as oauth server.

    If you will provide me the solution then it’s very good.

    Plugin Author Justin Greer

    (@justingreerbbi)

    We looked into the idea of this and have started implementing the feature into the server. We will then add the feature into our client plugin as well. Right now there is no timeline for the feature.

    We plan on starting development, tomorrow and is expected to take a week and then a couple of days for repo pushes.

    Thread Starter Gigabyteservice

    (@gigabyteservice)

    Thank you for the update

    Thread Starter Gigabyteservice

    (@gigabyteservice)

    I’m waiting for role based login feature

    Plugin Author Justin Greer

    (@justingreerbbi)

    @gigabyteservice,

    Thank you for checking back into the project for this feature. Since this is a feature for OAuth 2.0 and WordPress on the server-side of things, we have added a new action right before the issuing of an access token.

    The codebase is currently in the SVN trunk here on WP.org. In order to limit access tokens per user and client id, one could add the following snippet to a custom plugin or their themes functions.php file.

    /**
     * Example of only allow the role of administrator to for a given client.
     */
    add_action( 'wp_oauth_server_user_check', 'wp_oauth_server_user_check_callback', 2, 99 );
    function wp_oauth_server_user_check_callback( $clientId, $userId ) {
    
    	if ( $clientId == 'mvJsGPYZNHgRVSeoNQfrT4FN6wpunvVJ0FbHu9Hi' ) {
    		$user_meta  = get_userdata( $userId );
    		$user_roles = $user_meta->roles;
    		if ( ! in_array( 'subscriber', $user_roles ) ) {
    			wp_send_json( array(
    				'error' => 'invalid_request',
    				'error_description' => 'User role does not have authorization to make this request',
    			), 401 );
    			exit;
    		}
    	}
    }

    The action hook provides the given client ID and User ID. With this information, one could take the info and filter to and return an error (failed authorization/login) if the criteria do not match.

    Hi

    I’ll thank if you could tell me if this works in the free version.

    I’m getting this error: error/Could not decode JSON token response

    Thanks!

    Regards,
    Carlos.

    oops… I have read it again.. it’s not still deployed

    Sorry ??

    DOes this work now; for the free version of the OAUTH server software?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to allow only certain user role can do login’ is closed to new replies.