Authentification sans mot de passe Auth0.Android

La connexion sans mot de passe peut se faire par courriel ou par SMS, en envoyant à l’utilisateur un code ou un lien contenant un code. Toutes les méthodes d’authentification sans mot de passe nécessitent deux étapes : la demande du code, suivie de la saisie du code pour vérification.

Configurer la trousse SDK pour Android

Tout d’abord, configurez la trousse SDK Android de manière à pouvoir utiliser les méthodes sans mot de passe ci-dessous.

Configuration Auth0 et de la trousse SDK Android

Pour utiliser l’API sans mot de passe à partir d’un client natif, activez l’autorisation OTP sans mot de passe pour votre application dans Dashboard > Applications > (VOTRE APPLICATION) > Paramètres > Paramètres avancés > Types d’autorisation.

Demander le code

This example requests the code by calling passwordlessWithEmail with the user’s email, PasswordlessType.CODE, and the name of the connection as parameters. On success, you may want to notify the user that their code is on the way, and perhaps route them to where they will input that code.

authentication
    .passwordlessWithEmail("username@domain.com", PasswordlessType.CODE, "my-passwordless-connection")
    .start(object: Callback<Void?, AuthenticationException>() {
        override fun onSuccess(result: Void?) {
            // Code sent!
        }

        override fun onFailure(error: AuthenticationException) {
            // Error!
        }
    })

Was this helpful?

/

Vous pouvez utiliser la méthode passwordlessWithSms pour envoyer le code par SMS.

Saisir le code

Once the user has a code, they can input it. Call the loginWithEmail method and pass in the user’s email, the code they received, and the name of the connection in question. Upon success, you receive a Credentials object in the response.

authentication
    .loginWithEmail("username@domain.com", "123456", "my-passwordless-connection")
    .start(object: Callback<Credentials, AuthenticationException>() {
        override fun onSuccess(result: Credentials) {
            // Logged in!
        }

        override fun onFailure(error: AuthenticationException) {
            // Error!
        }
    })

Was this helpful?

/

Vous pouvez utiliser la méthode loginWithSms pour envoyer le code reçu par SMS et authentifier l’utilisateur.

La valeur par défaut de la permission est openid profile email.