SuperAPI AI 工具集

auth0-net-ios

通用与其它

查看项目

更新于 10-15 17:21

技能介绍

用途:在 .NET iOS 应用中添加 Auth0 认证,集成 Auth0.OidcClient.iOS NuGet 包,通过 ASWebAuthenticationSession 实现带 PKCE 的 OIDC 登录与登出。

主要能力:构造 /authorize URL(含 PKCE code verifier 与 challenge),打开系统浏览器完成登录、社交登录、MFA 等,回调后完成令牌交换,返回 access token、ID token、refresh token 与用户声明。

使用方式: 1)安装:dotnet add package Auth0.OidcClient.iOS 2)配置 Auth0Client,设置 Domain、ClientId,Scope 使用 openid profile email offline_access;iOS 无需传入 Activity 上下文。 3)回调 URL 格式为 {BundleId}://{domain}/ios/{BundleId}/callback,须全小写,并在 Auth0 Dashboard 的 Allowed Callback URLs 和 Allowed Logout URLs 中登记。 4)在 Info.plist 的 CFBundleURLSchemes 中注册与 Bundle Identifier 一致的 URL scheme。 5)在 AppDelegate 中重写 OpenUrl 并调用 ActivityMediator.Instance.Send(url.AbsoluteString)。 6)登录后用 iOS Keychain 持久化令牌,登出时清除。 7)验证:dotnet build。

前提:.NET 8.0 及以上(.NET 9 支持,目标框架 net9.0-ios)、macOS 与 Xcode 15+、iOS 14.0+、Auth0 中已配置 Native 应用、Node.js 20+(用于 Auth0 CLI 自动设置)。

限制与注意:不适用于 .NET MAUI、纯 Android .NET、纯 Swift iOS、ASP.NET Core 服务端与 Web API、React Native 等场景;应用类型须为 Native;Domain 只填主机名;不要在 UserDefaults 或仅内存中保存令牌;建议在真机上测试完整登录、回调与登出流程。