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

Can't authenticate non-admin users #51

Open
rakib205 opened this issue Jul 12, 2020 · 2 comments
Open

Can't authenticate non-admin users #51

rakib205 opened this issue Jul 12, 2020 · 2 comments

Comments

@rakib205
Copy link

rakib205 commented Jul 12, 2020

Hi there, I am trying to authenticate my users but i can't.
It shows always : WordPress Error! code: wp_empty_list, message: No users found, status: null

My code

Future signIn (String name, String password) async {
    wp.WordPress wordPress = wp.WordPress(
        baseUrl: config.websiteUrl,
        authenticator: wp.WordPressAuthenticator.JWT,
        adminKey: '',
        adminName: '');

    final response  = wordPress.authenticateUser(
        username: '******', password: '********');

    response.then((user) async{await wordPress.authenticateUser(username: name, password: password).then((p) {
      print("Success : $p");
    }).catchError((e) {
      print('error : $e');
    });
    }).catchError((e) {

    });
  }
@ellie-me
Copy link

Hey! I don't know if this can be useful but have a look at #38.
Basically what is happening is that the authenticateUser function calls fetch user after jwt authentication which in turns what it does is to search for an specific user in WordPress rather than doing the authentication with the user, your problem might be happening because on your WordPress installation you have your admin role outside of the users that the public REST api can fetch. I'm working in a fix for this and submit a pr as soon as I'm done as my app needs to handle properly user registration before launch.

Do something, go to postman, (download it from here if you don't have it) and make a GET request as follows, check if the problem is with your WordPress installation or if the problem is with this library, replace the parenthesis with your data: https://(myWordpressWebsite)/wp-json/wp/v2/users/?search=(adminemail@gmail.com)&

image

@ellie-me
Copy link

Hi there, I am trying to authenticate my users but i can't.
It shows always : WordPress Error! code: wp_empty_list, message: No users found, status: null

My code

Future signIn (String name, String password) async {
    wp.WordPress wordPress = wp.WordPress(
        baseUrl: config.websiteUrl,
        authenticator: wp.WordPressAuthenticator.JWT,
        adminKey: '',
        adminName: '');

    final response  = wordPress.authenticateUser(
        username: '******', password: '********');

    response.then((user) async{await wordPress.authenticateUser(username: name, password: password).then((p) {
      print("Success : $p");
    }).catchError((e) {
      print('error : $e');
    });
    }).catchError((e) {

    });
  }

Rakib I have found a solution, the main culprit is the default behaviour of WordPress itself, implementing authentication in WordPress is not that easy, as you require a specific setup to make it happen, there's a bit of refactoring needed for this library to handle incorrect login credentials, I tried to find a way to handle incorrect login credentials with the current version of the library "as is" but it needs refactoring, I don't know if this is too late for you, but if you are in a hurry and need to release something important you might have to handle for now authentication by doing manual http requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants