如何使用 ADFS 在 IOS 上实现 SSO 功能

How to implement SSO functionality on IOS using ADFS

我想使用 ADFSIOS 上实现 single sign-on 功能。 我做了一些研发并尝试了 MSAL iOS 库来进行 ADFS 身份验证,但它对我不起作用。

我已经为 ADFS 身份验证添加了客户端 ID、权限 URL,但它对我不起作用。每次它给我 Couldn't acquire token 错误。

我有不同的 SSO URL,所以没有使用 Microsoft azure server

我已尝试通过以下方式为 MSAL IOS 库添加我的凭据

let kClientID = "xxxxxx-8929-4D60-B869-xxxxxxxx"

// These settings you don't need to edit unless you wish to attempt deeper scenarios with the app.
let kGraphURI = "https://graph.microsoft.com/v1.0/me/"
let kScopes: [String] = ["https://graph.microsoft.com/user.read"]
let kAuthority = "https://fs.example.com/adfs/oauth2"

有什么想法吗?

这里我们不需要使用MSALiOS。有一个使用 Microsoft 文档的简单解决方案。在 link 之后:

https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/overview/ad-fs-scenarios-for-developers

我们只需要组成一个url字符串

https://fs.xxx.com/adfs/oauth2/authorize?response_type=code&client_id=xxxx-xxxx-xxxx-xxxx-xxxxxxx&redirect_uri=appName://&resource=http://xxxx/workflow

这将生成一个代码,我们可以在 App Delegate 的 openUrl 方法中获取该代码,然后我们需要使用参数创建一个 post 请求:

grant_type:authorization_code
code: xxxxx ( we got from get request)
redirect_uri: appName://
resource:http://xxxx/workflow

就是这样。我们将得到 access_token,我们可以进一步使用它来获取 userProfile 等

希望对您有所帮助!