com.mongodb.stitch.android.core.auth是MongoDB Stitch Android SDK已停用并迁移至MongoDB Realm中用于处理 Android 平台身份验证Authentication的核心包。该包提供了与 Stitch 后端服务交互的类支持多种认证方式如匿名登录、邮箱密码、第三方 OAuthGoogle、Facebook、Apple 等、自定义 JWT 登录等。⚠️ 重要背景MongoDB 宣布于2021 年底正式弃用 Stitch 平台其全部功能包括认证、同步、函数、数据库访问等已整合并升级为MongoDB Realm现统一称为MongoDB Atlas App Services。因此com.mongodb.stitch:stitch-android-sdk及其子包如com.mongodb.stitch.android.core.auth不再维护不兼容新 Android API如 Android 12 的隐私限制、targetSdkVersion ≥ 31 的 PendingIntent 要求等官方推荐迁移到io.realm:realm-android-sdk旧 Realm或更现代的io.realm:realm-android-library/io.realm:realm-android-kotlinRealm Kotlin或直接使用MongoDB Atlas App Services REST API officialmongodb-atlas-app-servicesSDK如com.mongodb.atlas:atlas-android-sdk。典型类Stitch 时代StitchAuth主认证管理器获取当前用户、登录/登出StitchUser表示已认证用户含id,profile,loginProvider,customData等AuthProvider/AnonymousAuthProvider,EmailPasswordAuthProvider,GoogleRedirectAuthProvider等各类认证提供者AuthResult/StitchAuthException登录结果与异常处理。✅ 迁移建议当前最佳实践使用 MongoDB Atlas App Services Android SDKcom.mongodb.atlas:atlas-android-sdk认证逻辑改用App→auth→loginWithCredential(...)支持相同认证方式匿名、邮箱密码、OAuth、API Key、Custom Token 等且与 Atlas 数据库、Functions、Triggers 深度集成。示例Stitch 已废弃写法 ❌StitchAppClientclientStitch.getDefaultAppClient();StitchAuthauthclient.getAuth();auth.loginWithCredential(newAnonymousCredential()).addOnCompleteListener(task-{if(task.isSuccessful()){Log.d(Auth,Logged in as: auth.getCurrentUser().getId());}});✅ 替代Atlas App Services 写法valappApp.Builder(your-app-id).build()valcredentialsCredentials.anonymous()app.loginAsync(credentials){result-if(result.isSuccess){Log.i(Auth,Logged in:${result.get().id})}else{Log.e(Auth,Login failed,result.error)}}如需进一步帮助如迁移步骤、配置 Gradle 依赖、处理 OAuth 重定向、或 Realm Kotlin 示例欢迎继续提问Package com.mongodb.stitch.android.core.authWas this page helpful?YesNoSkip navigation linksOverview Package Class Tree Deprecated Index Help SEARCH:Package com.mongodb.stitch.android.core.authThis package contains the auth interface used to log in into Stitch and the definition of a User.Interface Summary Interface Description StitchAuth StitchAuth manages authentication for any Stitch based client. StitchAuthListener StitchAuthListener listens to a StitchAuth instance for authentication events as they happen in a StitchAppClient. StitchUser A user that belongs to a MongoDB Stitch application.Skip navigation linksOverview Package Class Tree Deprecated Index Help