简体   繁体   中英

How to sign up and in with OAuth credentials in firebase and flutter?

I was reading in the firebase Auth Rest Api and found this OAuth Credentials that contains a lot of information about a user that signs in including if the email is verified, So I tried to do it in my flutter app but looks like I am missing sth called Request URI I am new to flutter and firebase so I need your help.

My code:

static Future signin(String email, String password) async {
    try {
      http.Response response = await http.post(
        'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=AIzaSyD3KOx9KSfK1lhyWRCt4_-dXLkKDNq-0hU',
        body: {
          'email': email,
          'password': password,
          'requestUri': ?? 'Sth of Type String',
        },
      );

      if (response.statusCode == 200) {
        print(response.statusCode);
        print(json.decode(response.body));
      } else {
        print(response.statusCode);
      }

      String jsonsDataString = response.body.toString();
      var _data = jsonDecode(jsonsDataString);
      print(_data.toString());
      print({email, password});

      if (response.body.contains('EMAIL_EXISTS')) {
        print('email exists');
      } else if (response.body.contains('WEAK_PASSWORD')) {
        print('weak password');
      }
    } catch (e) {
      print(e);
    }
  }

Your are using the API for signing in with via oAuth and the requestUri ist the redirect URL of the auth flow. Check this link: https://www.oauth.com/oauth2-servers/redirect-uris/

What you could do is use the sign-in with email api instead. Check https://firebase.google.com/docs/reference/rest/auth and search sign in with email / passwort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM