简体   繁体   English

如何在 firebase 和 flutter 中注册和使用 OAuth 凭据?

[英]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. 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称为请求 URI 我是 flutter 和 firebase 的新手,所以我需要你的帮助。

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.您正在使用 API 通过 oAuth 登录,并且 requestUri 是身份验证流的重定向 URL。 Check this link: https://www.oauth.com/oauth2-servers/redirect-uris/检查此链接: https://www.oauth.com/oauth2-servers/redirect-uris/

What you could do is use the sign-in with email api instead.您可以做的是使用 email api 登录。 Check https://firebase.google.com/docs/reference/rest/auth and search sign in with email / passwort.检查https://firebase.google.com/docs/reference/rest/auth并使用 email / 密码搜索登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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