Alternative API
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
-39%
Le deal à ne pas rater :
Pack Home Cinéma Magnat Monitor : Ampli DENON AVR-X2800H, Enceinte ...
1190 € 1950 €
Voir le deal

Aller en bas
Trxyy
Trxyy
Administrateur
Messages : 52
Date d'inscription : 28/04/2020
Localisation : Par là
https://alternativeapi.forumactif.com/

API Utiliser l'Authentification Microsoft

Mer 11 Aoû - 14:25

microsoft - Utiliser l'Authentification Microsoft Altern15


Utiliser l'authentification Microsoft






-[Pré-requis]-
1) Des connaissances en Java
2) Avoir fini le tutoriel Créer un launcher Minecraft Animé





1] Récupération & Ajout de la librairie

Pour commencer on va récupérer la librairie AlternativeAuth en cliquant ici
On récupère aussi l'image Microsoft à mettre sur le bouton en cliquant ici
Ensuite nous l'ajoutons à notre projet en la glissant dans le dossier lib
microsoft - Utiliser l'Authentification Microsoft Rvnv86A

Puis on va faire clique droit sur la librairie > Build Path > Add To Build Path


microsoft - Utiliser l'Authentification Microsoft VdxxH1X



2] Modification du code existant



Code:
private GameAuth gameAuthentication;
private LauncherButton microsoftButton;

Le GameAuth sera notre Objet Authentification
Le LauncherButton sera notre nouveau bouton pour l'authentification Microsoft


On va changer l'action du bouton de connexion (launcherButton)
Donc on remplace l'action par ceci


Code:
this.loginButton.setOnAction(new EventHandler<ActionEvent>() {
 public void handle(ActionEvent event) {
 config.updateValue("username", usernameField.getText());
 /**
 * ===================== AUTHENTIFICATION OFFLINE (CRACK) =====================
 */
 if (usernameField.getText().length() < 3) {
 new LauncherAlert("Authentification echouee",
 "Il y a un probleme lors de la tentative de connexion: Le pseudonyme doit comprendre au moins 3 caracteres.");
 } else if (usernameField.getText().length() > 3 && passwordField.getText().isEmpty()) {
 gameAuthentication = new GameAuth(usernameField.getText(), passwordField.getText(), AccountType.OFFLINE);
 if (gameAuthentication.isLogged()) {
 update(gameAuthentication);
 }
 }
 /** ===================== AUTHENTIFICATION OFFICIELLE ===================== */
 else if (usernameField.getText().length() > 3 && !passwordField.getText().isEmpty()) {
 gameAuthentication = new GameAuth(usernameField.getText(), passwordField.getText(), AccountType.MOJANG);
 if (gameAuthentication.isLogged()) {
 update(gameAuthentication);
 } else {
 new LauncherAlert("Authentification echouee!",
 "Impossible de se connecter, l'authentification semble etre une authentification 'en-ligne'"
 + " \nIl y a un probleme lors de la tentative de connexion. \n\n-Verifiez que le pseudonyme comprenne au minimum 3 caracteres. (compte non migrer)"
 + "\n-Faites bien attention aux majuscules et minuscules. \nAssurez-vous d'utiliser un compte Mojang.");
 }
 } else {
 new LauncherAlert("Authentification echouee!",
 "Impossible de se connecter, l'authentification semble etre une authentification 'hors-ligne'"
 + " \nIl y a un probleme lors de la tentative de connexion. \n\n-Verifiez que le pseudonyme comprenne au minimum 3 caracteres.");
 }
 }
 });



Ce changement sert juste à faire que l'on puisse utiliser le gameAuthentification que nous avons défini au dessus.


Maintenant nous ajoutons notre bouton Microsoft

Code:
this.microsoftButton = new LauncherButton(root);
 LauncherImage mcaImage = new LauncherImage(root, loadImage(theGameEngine, "microsoft.png"));
 mcaImage.setSize(20, 20);
 this.microsoftButton.setGraphic(mcaImage);
 this.microsoftButton.setBounds(20, 20, 20, 20);
 this.microsoftButton.setInvisible();
 this.microsoftButton.setOnAction(new EventHandler<ActionEvent>() {
 public void handle(ActionEvent event) {
 gameAuthentication = new GameAuth(AccountType.MICROSOFT);
 showMicrosoftAuth(gameAuthentication);
 if (gameAuthentication.isLogged()) {
 update(gameAuthentication);
 }
 }
 });


Par défaut, le bouton s'affichera en haut à gauche, place-le ou vous souhaitez.
Nous avons une erreur et c'est normal, nous allons maintenant ajouter les fonctions manquantes

Code:
private void showMicrosoftAuth(GameAuth auth) {
 Scene scene = new Scene(createMicrosoftPanel(auth));
 Stage stage = new Stage();
 scene.setFill(Color.TRANSPARENT);
 stage.setResizable(false);
 stage.setTitle("Microsoft Authentication");
 stage.setWidth(500);
 stage.setHeight(600);
 stage.setScene(scene);
 stage.initModality(Modality.APPLICATION_MODAL);
 stage.showAndWait();
 }
 
 private Parent createMicrosoftPanel(GameAuth auth) {
 LauncherPane contentPane = new LauncherPane(theGameEngine);
 auth.connectMicrosoft(contentPane);
 return contentPane;
 }

Maintenant votre connexion avec Microsoft est ajoutée et fonctionnelle.


microsoft - Utiliser l'Authentification Microsoft MzzxL0b



Un Grand merci à @Luuxis qui m'a offert la possibilité de faire mes tests.
Revenir en haut
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum