I've tried to use OAuth2 to authorize my app (written in flutter/dart), and here's what I got:
I/flutter ( 7002): {"error":"invalid_client","error_description":"Client authentication failed","message":"Client authentication failed"} I/flutter ( 7002): 401
And here's my code:
void getToken() async { Directory appDir = await getApplicationDocumentsDirectory(); String appDirUse = appDir.path; final codeChallenge = await File('$appDirUse/code_challenge').readAsString(); Uri sendToUri = Uri.parse('http://$fullServerName${wgScriptPath}rest.php/oauth2/authorize?response_type=code&client_id=$identifier&redirect_uri=$redirectUrl&code_challenge=$codeChallenge&code_challenge_method=S256'); await openInBrowser(sendToUri); } Future<void> openAppLink(String deepLink) async { String code = deepLink.replaceFirst("wikiapp://OAuth2?code=", ""); Directory appDir = await getApplicationDocumentsDirectory(); String appDirUse = appDir.path; final verifierFile = await File('$appDirUse/code_verifier').readAsString(); Uri sendToUri = Uri.parse("$kScheme://$fullServerName${wgScriptPath}rest.php/oauth2/access_token"); // openInBrowser(sendToUri); final response = await http.post( sendToUri,headers: headers, body: {'grant_type': 'client_credentials', 'client_id': identifier, 'code': code, 'redirect_uri': redirectUrl, 'code_verifier': verifierFile} ); }
I don't know what happened... Why it always 701 and Client authentication failed?