📲 Get Started with Android Authentication using Kotlin
Tags: android, kotlin, security
Published: 2021-10-01 14:56:13

#### 📓 Learn how to implement login, logout, and user profiles in Android apps using Kotlin and Auth0.

### <br>

If you’re planning to build a native Android app that requires users to log in, you should use Auth0. 

Implementing user login/logout often turns into its own project. Just implementing the many ways users want to log in can easily take a lot of time. You’d also have to deal with issues such as user management, scaling, and security, each of which could have its own article.

With Auth0 and a few lines of code, your app can have a full-featured system that supports logging in with a basic username/password combination, single sign-on and social accounts, passwordless login, biometrics, and more. You won’t have to handle the “behind the scenes” issues, either!

**This tutorial covers the basics of using Auth0 to implement login/logout in an Android app written in Kotlin.** It also provides an introduction to reading and writing information into user profiles so that your app can customize itself for each user. Along the way, you’ll become familiar with the Auth0 dashboard and learn how to use it to register applications and users.

> **Look for the 🛠 emoji if you’d like to skim through the content while focusing on the build and execution steps.** 


## What you’ll build

You’ll build a simple, single-screen Android app that will allow the user to log in and log out using Auth0. While logged in, the user will be able to see the following information from their user profile, namely:

* Information that is part and parcel of the user account, namely:
	* The user’s name
	* The user’s email address
* Metadata attached to the user account, namely:
	* The user’s country

The user will also be able to edit their country, and the result of that edit will be stored in the user account.

When you launch the completed app, you’ll see a greeting, a **Log in** button, and a disabled **Log out** button:

![The finished app’s screen when launched. The greeting “Welcome to the app!” appears above the “Log in” and “Log out” buttons.](https://images.ctfassets.net/23aumh6u8s0i/7FSXqzXczgaNUC5NnY9q1F/d72b55833d1bf446c70d60488f7f4ae0/welcome_screen.png)

Tapping the **Log in** button takes the user to the login screen, which appears in a custom Chrome tab:

![The default Auth0 login web page. It lets the user enter username and password or log in using a Google account.](https://images.ctfassets.net/23aumh6u8s0i/53TEQjPR0HhmvGIC8BXW7a/e7b6205b7c401883c61b162c498a00f7/universal_login.png)

When you use Auth0 in your apps, you delegate authentication to a centralized login page in the same way that Google properties such as Gmail and YouTube redirect you to **accounts.google.com** when you log in. In this exercise, you’ll use the default “look and feel” for the login page, but [you can customize it to match your app or organization’s branding](https://auth0.com/docs/universal-login/new-experience/universal-login-page-templates).

Logging in successfully returns you to the app, where you’ll see the following changes:

![The finished app’s screen when the user is logged in. It displays information about the logged-in user.](https://images.ctfassets.net/23aumh6u8s0i/6D4JdPU0s5tGuplX9gEE4g/cfb0e2c57ead91059a2d6a26d6efdf44/main_screen_1.png)

* The greeting will have changed to a notification telling you that you’re now logged into the app.
* The **Log in** button will now be disabled, and the **Log out** button will now be enabled.
* The name and email address for the user account that you used to log in will be displayed.
* There will now be a section for metadata, complete with an editable text box (an `EditText` in Android parlance) and **Get** and **Set** buttons that will allow you to read and write to the `country` field of the metadata for the user account.

As you might expect, logging out is done by tapping the **Log out** button. Once logged out, you see the following changes onscreen:

![The finished app’s screen when the user is logged out. The title bar reads “You’re logged out”.](https://images.ctfassets.net/23aumh6u8s0i/2JqJGGpuuMVwdXSPyHH0iT/8c4153360bd7aa656dccc8170af42e4d/logout_screen.png)

* The notification at the top of the screen will now inform you that you’re logged out of the app.
* Logging out enables the **Log in** button and disables the **Log out** button.
* The other controls that were visible when you were logged in will no longer be visible.

[Read more...](https://auth0.com/blog/get-started-with-android-authentication-using-kotlin-part-1/?utm_source=content_synd&utm_medium=sc&utm_campaign=android)