As we all know desktop application has no auth support so any one can help me with this.
Future<http.Response> signUp(
String email,
String password,
) async {
final uri =
Uri.parse("https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=$apiKey");
final headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer token',
};
Map<String, dynamic> body = {
"email": "[email protected]",
"password": "password",
"returnSecureToken":true,
};
String jsonBody = json.encode(body);
final encoding = Encoding.getByName('utf-8');
http.Response response = await http.post(
uri,
headers: headers,
body: jsonBody,
encoding: encoding,
);
print(response.statusCode);
print(response.body);
jsonResponse = json.decode(response.body);
// box.write("token", jsonResponse['refreshToken']);
// oneTimeToken = jsonResponse['refreshToken'];
// print(oneTimeToken);
if (box.read('token') != null) {
Fluttertoast.showToast(
msg: 'Account Created Successfully',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);;setState(() {
loading = false;
});
} else if (response.statusCode != 200) {
setState(() {
loading = false;
});
Fluttertoast.showToast(
msg: 'Account Already existing \n or missing data',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
}
return response;
}
Error:
flutter: {
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Invalid Credentials",
"domain": "global",
"reason": "authError",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
"metadata": {
"method": "google.cloud.identitytoolkit.v1.AuthenticationService.SignInWithPassword",
"service": "identitytoolkit.googleapis.com"
}
}
]
}
}
I am having this error can any one tell me what is this (OAuth 2 access token).I used this code on mongodb Works fine.
or
if anyone have any other solution it will be big help if provided. thankyou.
get solution for flutter desktop auth.
Assuming you are NOT using OAuth 2.0 for your API, remove the authorization header from your sign up request and it should work.
Try it out on the command line using your API key
https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/signUp
https://support.google.com/googleapi/answer/6158862?hl=en&ref_topic=7013279
https://support.google.com/googleapi/answer/6158849?hl=en&ref_topic=7013279
https://developers.google.com/identity/protocols/OAuth2#libraries