# Authentication flows

Use `Auth` for sign-in and sign-up flows, and to manage sessions. You can access auth with `Clerk.auth`.

## Sign in

### Sign in with password

Sign in directly with an identifier (email, phone, or username) and password:

```kotlin
val signIn = Clerk.auth.signInWithPassword {
    identifier = "user@email.com"
    password = "secretpassword"
}
```

### Sign in with OTP (email)

Send an OTP to the supplied email, and then verify the code.

```kotlin
var signIn = Clerk.auth.signInWithOtp { email = "user@email.com" }
signIn = signIn.verifyCode("123456")
```

### Sign in with OTP (phone)

Send an OTP to the supplied phone number, and then verify the code.

```kotlin
var signIn = Clerk.auth.signInWithOtp { phone = "+1234567890" }
signIn = signIn.verifyCode("123456")
```

### Sign in with OAuth

Sign in using an OAuth provider (e.g., Google, GitHub, see [all providers](https://clerk.com/docs/android/guides/configure/auth-strategies/social-connections/overview.md#supported-social-providers)):

```kotlin
val result = Clerk.auth.signInWithOAuth(OAuthProvider.GOOGLE)
```

### Sign in with ID token

Sign in with an ID token from a provider:

```kotlin
val result = Clerk.auth.signInWithIdToken {
    token = idToken
    provider = IdTokenProvider.GOOGLE
}
```

### Sign in with passkey

Sign in using a passkey:

```kotlin
val signIn = Clerk.auth.signInWithPasskey()
```

### Sign in with Enterprise SSO

Sign in using [Enterprise SSO](https://clerk.com/docs/guides/configure/auth-strategies/enterprise-connections/overview.md?sdk=android):

```kotlin
val result = Clerk.auth.signInWithEnterpriseSso { email = "user@company.com" }
```

### Sign in with ticket

Sign in using a ticket generated from the Backend API:

```kotlin
val signIn = Clerk.auth.signInWithTicket(ticket)
```

### Sign in with identifier

Start a sign-in with an identifier (email, phone, or username):

```kotlin
// Email
var signIn = Clerk.auth.signIn { email = "user@email.com" }
```

```kotlin
// Phone
var signIn = Clerk.auth.signIn { phone = "+1234567890" }
```

```kotlin
// Username
var signIn = Clerk.auth.signIn { username = "johndoe" }
```

### Continue an existing sign-in

Use these methods when you already have a `SignIn` from `Clerk.auth.signIn { ... }` and want to complete it with a specific factor or provider.

#### Send and verify email code

Send the user an OTP via email to verify their sign-in. Then verify the code that the user supplies:

```kotlin
signIn = signIn.sendEmailCode()
signIn = signIn.verifyCode("123456")
```

#### Send and verify phone code

Send the user an OTP via SMS to verify their sign-in. Then verify the code that the user supplies:

```kotlin
signIn = signIn.sendPhoneCode()
signIn = signIn.verifyCode("123456")
```

#### Authenticate with password

```kotlin
signIn = signIn.verifyWithPassword("secretpassword")
```

#### Authenticate with passkey

```kotlin
signIn = signIn.verifyWithPasskey(credential)
```

### Multi-factor authentication

After completing first factor verification, if multi-factor authentication (MFA) is required, use these methods to complete the second factor verification. The examples assume you already have a `SignIn` from a sign-in flow.

#### MFA with phone code

Send and verify an MFA code via SMS:

```kotlin
signIn = signIn.sendMfaPhoneCode()
signIn = signIn.verifyMfaCode("123456", MfaType.PHONE_CODE)
```

#### MFA with email code

Send and verify an MFA code via email:

```kotlin
signIn = signIn.sendMfaEmailCode()
signIn = signIn.verifyMfaCode("123456", MfaType.EMAIL_CODE)
```

#### MFA with TOTP (authenticator app)

Verify using a TOTP code from an authenticator app:

```kotlin
signIn = signIn.verifyMfaCode("123456", MfaType.TOTP)
```

#### MFA with backup code

Verify using a backup code:

```kotlin
signIn = signIn.verifyMfaCode("backup123", MfaType.BACKUP_CODE)
```

### Password reset

The Clerk Android SDK provides methods to reset user passwords via email or phone verification.

#### Password reset with email

Reset password using email verification:

```kotlin
var signIn = Clerk.auth.signIn { email = "user@email.com" }
signIn = signIn.sendResetPasswordCode { email = "user@email.com" }
signIn = signIn.verifyCode("123456")
signIn = signIn.resetPassword(newPassword = "newpassword", signOutOfOtherSessions = true)
```

#### Password reset with phone

Reset password using phone verification:

```kotlin
var signIn = Clerk.auth.signIn { phone = "+1234567890" }
signIn = signIn.sendResetPasswordCode { phone = "+1234567890" }
signIn = signIn.verifyCode("123456")
signIn = signIn.resetPassword(newPassword = "newpassword", signOutOfOtherSessions = true)
```

## Sign up

### Create a new sign-up

Create a new account:

```kotlin
val signUp = Clerk.auth.signUp {
    email = "newuser@email.com"
    phone = "+1234567890"
    password = "secretpassword"
    firstName = "John"
    lastName = "Doe"
    username = "johndoe"
    legalAccepted = true
}
```

### Update a sign-up

Update sign-up information:

```kotlin
signUp = signUp.update {
    email = "newuser@email.com"
    phone = "+1234567890"
    password = "secretpassword"
    firstName = "John"
    lastName = "Doe"
    username = "johndoe"
    legalAccepted = true
}
```

### Sign up with OAuth

Sign up using an OAuth provider (e.g., Google, GitHub, see [all providers](https://clerk.com/docs/android/guides/configure/auth-strategies/social-connections/overview.md#supported-social-providers)):

```kotlin
val result = Clerk.auth.signUpWithOAuth(OAuthProvider.GOOGLE)
```

### Sign up with ID token

Sign up using an ID token:

```kotlin
val result = Clerk.auth.signUpWithIdToken(idToken, IdTokenProvider.GOOGLE) {
    firstName = "John"
    lastName = "Doe"
}
```

### Sign up with Enterprise SSO

Sign up using [Enterprise SSO](https://clerk.com/docs/guides/configure/auth-strategies/enterprise-connections/overview.md?sdk=android):

```kotlin
val result = Clerk.auth.signUpWithEnterpriseSso { email = "user@company.com" }
```

### Sign up with ticket

Sign up using a ticket generated from the Backend API:

```kotlin
val signUp = Clerk.auth.signUpWithTicket(ticket)
```

### Continue an existing sign-up

Use these methods when you already have a `SignUp` from `Clerk.auth.signUp { ... }` and want to complete it with a specific factor or provider.

### Send and verify email via OTP

Send the user an OTP via email to verify their account. Then verify the code that the user supplies:

```kotlin
signUp = signUp.sendEmailCode()
signUp = signUp.verifyCode("123456", VerificationType.EMAIL)
```

### Send and verify phone via OTP

Send the user an OTP via SMS to verify their account. Then verify the code that the user supplies:

```kotlin
signUp = signUp.sendPhoneCode()
signUp = signUp.verifyCode("654321", VerificationType.PHONE)
```

## Current sign-in/sign-up

Access the in-progress sign-in or sign-up stored on the client for multi-step flows.

### Current sign-in

```kotlin
val currentSignIn = Clerk.auth.currentSignIn
```

### Current sign-up

```kotlin
val currentSignUp = Clerk.auth.currentSignUp
```

## Session management

The Clerk Android SDK provides methods to manage user sessions, including signing out, switching sessions, and revoking sessions.

### Sessions

Retrieve all sessions for the current client:

```kotlin
val sessions = Clerk.client.sessions
```

### Get session token

Retrieve the user's session token:

```kotlin
val token = Clerk.auth.getToken()

// or with options
val token = Clerk.auth.getToken(GetTokenOptions(template = "my-template"))
```

### Set current session

Set the current session and optionally the Active Organization:

```kotlin
Clerk.auth.setActive(sessionId = sessionId, organizationId = organizationId)
```

### Revoke session

Revoke a specific session:

```kotlin
Clerk.auth.revokeSession(session)
```

### Sign out

Sign out the current user:

```kotlin
// Sign out from the current session
Clerk.auth.signOut()

// Sign out from a specific session
Clerk.auth.signOut(sessionId = sessionId)
```

## Deep linking

Handle OAuth/SSO deep link callbacks in your Activity:

```kotlin
// In your Activity's onCreate or onNewIntent
Clerk.auth.handle(intent.data)
```

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
