I am building a flutter app and I want users to be able to authenticate using their wordpress credentials.
I am using https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/#description and https://github.com/dreamsoftin/flutter_wordpress to make it easier.
import 'package:flutter/material.dart';
import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
void main() => runApp(MyApp());
wp.WordPress wordPress = wp.WordPress(
baseUrl: 'https://sandbox.myfprod.fr/',
authenticator: wp.WordPressAuthenticator.JWT,
adminName: '',
adminKey: '',
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: Container(
child: Column(
children: <Widget>[
TextField(
obscureText: false,
decoration: InputDecoration(labelText: 'Email'),
),
TextField(
obscureText: false,
decoration: InputDecoration(labelText: 'Password'),
),
RaisedButton(
child: Text('Login'),
onPressed: () {
Future<wp.User> response = wordPress.authenticateUser(
username: '•••••••••••',
password: '•••••••••••',
);
response.then((user) {
print(user);
}).catchError((err) {
print('Failed to fetch user: $err');
});
},
)
],
),
),
),
),
);
}
}
This code works only if the user has the role of administrator and I want to authenticate all users regardless of their role.
And I also have another issue : I don't have access to all user properties. For example email.email
returns null