Logto は、モダンなアプリや SaaS 製品向けに設計された Auth0 の代替です。 Cloud と オープンソース の両方のサービスを提供し、アイデンティティと管理 (IAM) システムを迅速に立ち上げるのをサポートします。 認証 (Authentication)、認可 (Authorization)、マルチテナント管理を すべて一つに まとめて楽しめます。
Logto Cloud で無料の開発テナントから始めることをお勧めします。これにより、すべての機能を簡単に探索できます。
この記事では、Android (Kotlin / Java) と Logto を使用して、Microsoft Entra ID SAML enterprise SSO サインイン体験(ユーザー認証 (Authentication))を迅速に構築する手順を説明します。
前提条件
- 実行中の Logto インスタンス。始めるには 紹介ページ をご覧ください。
- Android (Kotlin / Java) の基本的な知識。
- 使用可能な Microsoft Entra ID SAML enterprise SSO アカウント。
Create an application in Logto
Logto は OpenID Connect (OIDC) 認証 (Authentication) と OAuth 2.0 認可 (Authorization) に基づいています。複数のアプリケーション間でのフェデレーテッドアイデンティティ管理をサポートしており、一般的にシングルサインオン (SSO) と呼ばれます。
あなたの ネイティブアプリ アプリケーションを作成するには、次の手順に従ってください:
- Logto コンソール を開きます。「Get started」セクションで「View all」リンクをクリックしてアプリケーションフレームワークのリストを開きます。あるいは、Logto Console > Applications に移動し、「Create application」ボタンをクリックします。
- 開いたモーダルで、左側のクイックフィルターチェックボックスを使用して、すべての利用可能な "ネイティブアプリ" フレームワークをフィルタリングするか、"ネイティブアプリ" セクションをクリックします。"Android (Kotlin)" / "Android (Java)" フレームワークカードをクリックして、アプリケーションの作成を開始します。
- アプリケーション名を入力します。例:「Bookstore」と入力し、「Create application」をクリックします。
🎉 タダーン!Logto で最初のアプリケーションを作成しました。詳細な統合ガイドを含むお祝いページが表示されます。ガイドに従って、アプリケーションでの体験がどのようになるかを確認してください。
Integrate Android (Kotlin) / Android (Java) SDK
- この例は View システム と View Model に基づいていますが、Jetpack Compose を使用する場合でも概念は同じです。
- この例は Kotlin で書かれていますが、Java でも概念は同じです。
- Kotlin と Java のサンプルプロジェクトは、私たちの SDK リポジトリ で利用可能です。
- チュートリアルビデオは、私たちの YouTube チャンネル で視聴できます。
インストール
Logto Android SDK のサポートされている最小 Android API レベルはレベル 24 です。
Logto Android SDK をインストールする前に、Gradle プロジェクトのビルドファイルで mavenCentral()
がリポジトリ設定に追加されていることを確認してください:
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
Logto Android SDK を依存関係に追加します:
- Kotlin
- Groovy
dependencies {
implementation("io.logto.sdk:android:1.1.3")
}
dependencies {
implementation 'io.logto.sdk:android:1.1.3'
}
SDK はインターネットアクセスが必要なため、次の権限を AndroidManifest.xml
ファイルに追加する必要があります:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- インターネット権限を追加 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- その他の設定... -->
</manifest>
LogtoClient の初期化
LogtoViewModel.kt
を作成し、このビューモデルで LogtoClient
を初期化します:
//...他のインポート
import io.logto.sdk.android.LogtoClient
import io.logto.sdk.android.type.LogtoConfig
class LogtoViewModel(application: Application) : AndroidViewModel(application) {
private val logtoConfig = LogtoConfig(
endpoint = "<your-logto-endpoint>",
appId = "<your-app-id>",
scopes = null,
resources = null,
usingPersistStorage = true,
)
private val logtoClient = LogtoClient(logtoConfig, application)
companion object {
val Factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(
modelClass: Class<T>,
extras: CreationExtras
): T {
// extras から Application オブジェクトを取得
val application = checkNotNull(extras[APPLICATION_KEY])
return LogtoViewModel(application) as T
}
}
}
}
次に、MainActivity.kt
のために LogtoViewModel
を作成します:
//...他のインポート
class MainActivity : AppCompatActivity() {
private val logtoViewModel: LogtoViewModel by viewModels { LogtoViewModel.Factory }
//...他のコード
}
リダイレクト URI の設定
Logto コンソールのアプリケーション詳細ページに切り替えましょう。リダイレクト URI io.logto.android://io.logto.sample/callback
を追加し、「変更を保存」をクリックします。
サインインとサインアウトの実装
logtoClient.signIn
を呼び出す前に、Admin Console でリダイレクト URI
が正しく設定されていることを確認してください。 :::
logtoClient.signIn
を使用してユーザーをサインインし、logtoClient.signOut
を使用してユーザーをサインアウトできます。
例えば、Android アプリでは次のようにします:
//...他のインポートと共に
class LogtoViewModel(application: Application) : AndroidViewModel(application) {
// ...他のコード
// 認証 (Authentication) 状態を監視するライブデータを追加
private val _authenticated = MutableLiveData(logtoClient.isAuthenticated)
val authenticated: LiveData<Boolean>
get() = _authenticated
fun signIn(context: Activity) {
logtoClient.signIn(context, "io.logto.android://io.logto.sample/callback") { logtoException ->
logtoException?.let { println(it) }
// ライブデータを更新
_authenticated.postValue(logtoClient.isAuthenticated)
}
}
fun signOut() {
logtoClient.signOut { logtoException ->
logtoException?.let { println(it) }
// ライブデータを更新
_authenticated.postValue(logtoClient.isAuthenticated)
}
}
}
次に、アクティビティ内で signIn
と signOut
メソッドを呼び出します:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
//...他のコード
// レイアウトに id "sign_in_button" を持つボタンがあると仮定
val signInButton = findViewById<Button>(R.id.sign_in_button)
signInButton.setOnClickListener {
logtoViewModel.signIn(this)
}
// レイアウトに id "sign_out_button" を持つボタンがあると仮定
val signOutButton = findViewById<Button>(R.id.sign_out_button)
signOutButton.setOnClickListener {
if (logtoViewModel.authenticated) { // ユーザーが認証 (Authentication) されているか確認
logtoViewModel.signOut()
}
}
// 認証 (Authentication) 状態を監視して UI を更新
logtoViewModel.authenticated.observe(this) { authenticated ->
if (authenticated) {
// ユーザーは認証 (Authentication) されています
signInButton.visibility = View.GONE
signOutButton.visibility = View.VISIBLE
} else {
// ユーザーは認証 (Authentication) されていません
signInButton.visibility = View.VISIBLE
signOutButton.visibility = View.GONE
}
}
}
}
チェックポイント: アプリケーションをテストする
これで、アプリケーションをテストできます:
- アプリケーションを実行すると、サインインボタンが表示されます。
- サインインボタンをクリックすると、SDK がサインインプロセスを初期化し、Logto のサインインページにリダイレクトされます。
- サインインすると、アプリケーションに戻り、サインアウトボタンが表示されます。
- サインアウトボタンをクリックして、トークンストレージをクリアし、サインアウトします。
Add Microsoft Entra ID SAML enterprise SSO connector
To simplify access management and gain enterprise-level safeguards for your big clients, connect with Android (Kotlin) / Android (Java) as a federated identity provider. The Logto enterprise SSO connector helps you establish this connection in minutes by allowing several parameter inputs.
To add an enterprise SSO connector, simply follow these steps:
- Navigate to Logto console > Enterprise SSO.
- Click "Add enterprise connector" button and choose your SSO provider type. Choose from prebuilt connectors for Microsoft Entra ID (Azure AD), Google Workspace, and Okta, or create a custom SSO connection using the standard OpenID Connect (OIDC) or SAML protocol.
- Provide a unique name (e.g., SSO sign-in for Acme Company).
- Configure the connection with your IdP in the "Connection" tab. Check the guides above for each connector types.
- Customize the SSO experience and enterprise’s email domain in the "Experience" tab. Users sign in with the SSO-enabled email domain will be redirected to SSO authentication.
- Save changes.
Set up Azure AD SSO アプリケーション
ステップ 1: Azure AD SSO アプリケーションを作成する
Azure AD SSO 統合を開始するには、Azure AD 側で SSO アプリケーションを作成します。
- Azure ポータル にアクセスし、管理者としてサインインします。
Microsoft Entra ID
サービスを選択します。- サイドメニューを使用して
Enterprise applications
に移動します。New application
をクリックし、Create your own application
を選択します。
- アプリケーション名を入力し、
Integrate any other application you don't find in the gallery (Non-gallery)
を選択します。 Setup single sign-on
>SAML
を選択します。
- 指示に従い、最初のステップとして、Logto によって提供される以下の情報を使用して基本的な SAML 構成を入力する必要があります。
- Audience URI(SP Entity ID): これは、Logto サービスのグローバルに一意の識別子として機能し、IdP への認証リクエスト中に SP の EntityId として機能します。この識別子は、IdP と Logto 間で SAML アサーションやその他の認証関連データを安全に交換するために重要です。
- ACS URL: アサーションコンシューマーサービス (ACS) URL は、POST リクエストで SAML アサーションが送信される場所です。この URL は、IdP が SAML アサーションを Logto に送信するために使用されます。これは、ユーザーのアイデンティティ情報を含む SAML 応答を受信し消費することを Logto が期待するコールバック URL として機能します。
Save
をクリックして続行します。
ステップ 2: Logto で SAML SSO を設定する
SAML SSO 統合を機能させるには、IdP メタデータを Logto に戻す必要があります。Logto 側に戻り、Azure AD SSO コネクターの Connection
タブに移動しましょう。
Logto は、IdP メタデータを構成するための 3 つの異なる方法を提供しています。最も簡単な方法は、Azure AD SSO アプリケーションの metadata URL
を提供することです。
Azure AD SSO アプリケーションの SAML Certificates セクション
から App Federation Metadata Url
をコピーし、それを Logto の Metadata URL
フィールドに貼り付けます。
Logto は URL からメタデータを取得し、SAML SSO 統合を自動的に構成します。
ステップ 3: ユーザー属性のマッピングを設定する
Logto は、IdP から返されるユーザー属性を Logto のユーザー属性にマッピングする柔軟な方法を提供します。Logto はデフォルトで次のユーザー属性を IdP から同期します:
- id: ユーザーの一意の識別子。Logto は SAML レスポンスから
nameID
クレームを読み取り、ユーザーの SSO アイデンティティ ID として使用します。 - email: ユーザーのメールアドレス。Logto はデフォルトで SAML レスポンスから
email
クレームを読み取り、ユーザーのプライマリメールとして使用します。 - name: ユーザーの名前。
ユーザー属性のマッピングロジックは、Azure AD 側または Logto 側のいずれかで管理できます。
-
AzureAD ユーザー属性を Logto ユーザー属性に Logto 側でマッピングする。
Azure AD SSO アプリケーションの
Attributes & Claims
セクションにアクセスします。次の属性名(名前空間プレフィックス付き)をコピーし、Logto の対応するフィールドに貼り付けます。
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
(推奨:この属性値マップをuser.displayname
に更新して、より良いユーザー体験を提供する)
-
AzureAD ユーザー属性を AzureAD 側で Logto ユーザー属性にマッピングする。
Azure AD SSO アプリケーションの
Attributes & Claims
セクションにアクセスします。Edit
をクリックし、Logto ユーザー属性設定に基づいてAdditional claims
フィールドを更新します:- Logto ユーザー属性設定に基づいてクレーム名の値を更新します。
- 名前空間プレフィックスを削除します。
Save
をクリックして続行します。
次の設定で終了する必要があります:
Azure AD 側で追加のユーザー属性を指定することもできます。Logto は、ユーザーの sso_identity
フィールドの下に IdP から返された元のユーザー属性の記録を保持します。
ステップ 4: Azure AD SSO アプリケーションにユーザーを割り当てる
Azure AD SSO アプリケーションの Users and groups
セクションにアクセスします。Add user/group
をクリックして、ユーザーを Azure AD SSO アプリケーションに割り当てます。Azure AD SSO アプリケーションに割り当てられたユーザーのみが、Azure AD SSO コネクターを通じて認証 (Authentication) することができます。
ステップ 5: メールドメインを設定し、SSO コネクターを有効にする
Logto のコネクター SSO 体験
タブで、あなたの組織の メールドメイン
を提供してください。これにより、これらのユーザーに対する認証 (Authentication) 方法として SSO コネクターが有効になります。
指定されたドメインのメールアドレスを持つユーザーは、唯一の認証 (Authentication) 方法として SAML SSO コネクターを使用するようにリダイレクトされます。
Azure AD SSO 統合の詳細については、Azure AD の公式 ドキュメント を確認してください。
Save your configuration
Logto コネクター設定エリアで必要な値をすべて記入したことを確認してください。「保存して完了」または「変更を保存」をクリックすると、Microsoft Entra ID SAML enterprise SSO コネクターが利用可能になります。
Enable Microsoft Entra ID SAML enterprise SSO connector in Sign-in Experience
You don’t need to configure enterprise connectors individually, Logto simplifies SSO integration into your applications with just one click.
- Navigate to: Console > Sign-in experience > Sign-up and sign-in.
- Enable the "Enterprise SSO" toggle.
- Save changes.
Once enabled, a "Single Sign-On" button will appear on your sign-in page. Enterprise users with SSO-enabled email domains can access your services using their enterprise identity providers (IdPs).
To learn more about the SSO user experience, including SP-initiated SSO and IdP-initiated SSO, refer to User flows: Enterprise SSO.
Testing and Validation
Android (Kotlin / Java) アプリに戻ります。これで Microsoft Entra ID SAML enterprise SSO を使用してサインインできるはずです。お楽しみください!
Further readings
エンドユーザーフロー:Logto は、MFA やエンタープライズシングルサインオン (SSO) を含む即時使用可能な認証 (Authentication) フローを提供し、アカウント設定、セキュリティ検証、マルチテナント体験の柔軟な実装のための強力な API を備えています。
認可 (Authorization):認可 (Authorization) は、ユーザーが認証 (Authentication) された後に行えるアクションやアクセスできるリソースを定義します。ネイティブおよびシングルページアプリケーションの API を保護し、ロールベースのアクセス制御 (RBAC) を実装する方法を探ります。
組織 (Organizations):特にマルチテナント SaaS や B2B アプリで効果的な組織機能は、テナントの作成、メンバー管理、組織レベルの RBAC、およびジャストインタイムプロビジョニングを可能にします。
顧客 IAM シリーズ:顧客(または消費者)アイデンティティとアクセス管理に関する連続ブログ投稿で、101 から高度なトピックまでを網羅しています。