0

Meus scripts abaixo.

Classe utilitária principal.

public class SignInAuth {

  private DataOutputStream output;
  private BufferedReader reader;
  private URL url;
  private HttpURLConnection post;

  private Runnable run;
  private Credential credent;
  private String apiPath;

  public SignInAuth(String api) {
    String apiweb = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + api;
    this.apiPath = apiweb;
  }

  public void setCredentiais(Credential credent) {
    this.credent = credent;
  }

  public void createUserWithEmailAndPassword() {
    run =
        new Runnable() {
          public void run() {
            try {
              /// Code
              String data = "{\"email\": \"" + credent.email + "\",\"password\": \"" + credent.password + "\",\"displayName\": \"" + credent.name + "\",\"returnSecureToken\": true}";
              Console.log("Credentiais \n" + data);
              url = new URL(apiPath);
              post = (HttpURLConnection) url.openConnection();
              post.setRequestMethod("POST");
              post.setRequestProperty("Content-Type", "application/json");
              post.setDoOutput(true);

              output = new DataOutputStream(post.getOutputStream());
              output.writeBytes(data);
              output.flush();
              output.close();

              int responseCode = post.getResponseCode();
              if (responseCode == HttpURLConnection.HTTP_OK) {
                Console.log("User created in FirebaseAuth successfully.");
              } else {
                Console.log("Failed to create user in FirebaseAuth. Response Code: " + responseCode);
              } 
            } catch (IOException e) {
              /// Exception Code
              Console.log(e.getMessage());
            }
          }
        };

    new Thread(run).start();
  }
}

Utilitário

public class Credential {
    public String name;
    public String email;
    public String password;
    
}

0

Você deve fazer log-in para responder a esta pergunta.

Pesquise outras perguntas com a tag .