> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-actions-triggers-prototype.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Auth0.Androidのログイン、ログアウト、およびユーザープロファイル

> Android SDKを使用してログイン、ログアウトを追加し、ユーザープロファイルを読み込む方法を説明します。

## Androidアプリケーションにログインを追加する

`WebAuthProvider.login`メソッドを使用して、ユーザーをログインさせることができます。

```kotlin lines theme={null}
WebAuthProvider.login(account)
  .withScheme(getString(R.string.com_auth0_scheme))
  .withScope("openid profile email")
  .start(this, object : Callback<Credentials, AuthenticationException> {
    override fun onFailure(exception: AuthenticationException) {
       // Authentication failed
     }

      override fun onSuccess(credentials: Credentials) {
         // Authentication succeeded
       }
  })
```

認証結果は`onSuccess`コールバックに配信されます。

`WebAuthProvider`クラスのその他のオプションについては、「[Auth0.Androidの構成](/docs/ja-jp/libraries/auth0-android/auth0-android-configuration)」を参照してください。

## Androidアプリケーションにログアウトを追加する

ユーザーをログアウトさせるには、`WebAuthProvider.logout`メソッドを呼び出します。ログアウト結果は`onSuccess`コールバックに配信されます。

この方法では、認証時にブラウザが設定したCookieが削除されるため、ユーザーは次回認証を行うときに資格情報を再入力する必要があります。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  ログアウトがキャンセルされた場合は、ユーザーを、ログアウトの直前にいた場所に戻すといいかもしれません。
</Callout>

```kotlin lines theme={null}
WebAuthProvider.logout(account)
  .withScheme("demo")
  .start(this, object: Callback<Void?, AuthenticationException> {
    override fun onSuccess(payload: Void?) {
      // The user has been logged out!
    }

    override fun onFailure(error: AuthenticationException) {
      // Something went wrong!
    }
  })
```

## ユーザープロファイルを表示する

`AuthenticationAPIClient`クラスを使用して、Auth0からユーザーのプロファイルを取得します。これには以下のものが必要です。

* ログインフェーズで受信したアクセストークン
* `WebAuthProvider.login`が呼び出されたときを含むための`profile`スコープ
* `email`スコープ（ユーザーのメールアドレスを取得したい場合）

このサンプルはユーザープロファイルを取得して画面に表示する機能のデモです。

```kotlin lines theme={null}
var client = AuthenticationAPIClient(account)

// Use the received access token to call `userInfo` and get the profile from Auth0.
client.userInfo(accessToken)
  .start(object : Callback<UserProfile, AuthenticationException> {
      override fun onFailure(exception: AuthenticationException) {
          // Something went wrong!
      }

      override fun onSuccess(profile: UserProfile) {
        // We have the user's profile!
        val email = profile.email
        val name = profile.name
      }
})
```
