如何将 Azure Active Directory (Azure AD) 作为 SAML IdP 对接到 Keycloak

✅ 一、在 Azure AD 创建 SAML 应用

🔧 1. 登录 Azure 门户

前往 https://portal.azure.com,使用管理员账号登录。

📌 2. 创建企业应用(Enterprise Application)

  • 左侧菜单进入 "企业应用程序"
  • 点击 "新建应用程序"
  • 选择 "从库中创建" → 搜索 "Non-gallery application",起一个名字,比如 Keycloak SAML → 创建。

🔗 3. 配置 SAML 登录方式

  • 进入你刚创建的应用 → 左侧选择 "单一登录" → 选择 SAML

  • 点击第一步【基本 SAML 配置】的编辑图标 ✏️,填写:

    字段
    Identifier (Entity ID) https://<keycloak-host>/realms/<realm-name>
    Reply URL (Assertion Consumer Service URL) https://<keycloak-host>/realms/<realm-name>/broker/<idp-alias>/endpoint

    示例:

    复制代码
    Identifier: https://sso.example.com/realms/demo
    Reply URL: https://sso.example.com/realms/demo/broker/azure-ad/endpoint
  • 保存。


📎 4. 下载 IdP Metadata

在 Azure SAML 设置页面第 3 步,找到:

  • Federation Metadata XML:复制 URL 或下载 XML 文件。

✅ 二、在 Keycloak 中配置 Azure AD 作为 SAML IdP

➕ 添加 SAML IdP

  1. Keycloak 管理后台 → Identity Providers → 选择 SAML v2.0
  2. 填写以下字段:
字段
Alias azure-ad(你自定义的 IdP 别名)
Import from URL 粘贴 Azure 的 Metadata URL,或上传 XML 文件
First Login Flow 可以使用默认的 first broker login,也可以自定义跳过填写资料(见上条)

其他字段通常 Keycloak 会自动填好。

  1. 保存。

👤 映射 Azure 返回的属性

切换到 Mappers 标签,添加如下属性映射(根据 Azure 返回的内容而定):

Mapper Name Mapper Type SAML Attribute Name User Attribute
email Attribute Importer http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress email
first name Attribute Importer http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname firstName
last name Attribute Importer http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname lastName
username Attribute Importer http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name username

Azure AD 默认返回的字段是长 URI 格式。


✅ 三、让 Azure AD 知道 Keycloak 是谁

你可以将以下地址(SP Metadata)发给 Azure 管理员参考:

复制代码
https://<keycloak-host>/realms/<realm-name>/broker/<idp-alias>/endpoint/descriptor

✅ 四、测试登录

用户可以通过以下 URL 自动跳转到 Azure AD 登录:

复制代码
https://<keycloak-host>/realms/<realm-name>/protocol/openid-connect/auth?client_id=<client-id>&redirect_uri=<redirect-uri>&response_type=code&kc_idp_hint=azure-ad

🔄 可选:自定义首次登录行为(跳过填写资料)

可以结合上面提到的:

  • 修改 First Broker Login Flow
  • 映射好用户信息字段

就能避免用户登录后看到"Update Account Info"页面。

相关推荐
QWQ___qwq12 小时前
Swift中.gesture的用法
服务器·microsoft·swift
十五年专注C++开发13 小时前
CFF Explorer: 一款Windows PE 文件分析的好工具
c++·windows·microsoft
Q_Q51100828519 小时前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
codeの诱惑20 小时前
Azure DevOps CI/CD 流水线中 Java 17 容器化部署 NullPointerException 解决方案
ci/cd·azure·devops
Q_Q5110082851 天前
python+uniapp基于微信小程序的学院设备报修系统
spring boot·python·微信小程序·django·flask·uni-app
荔园微风2 天前
微软ML.NET技术详解:从数据科学到生产部署的全栈解决方案
microsoft·.net
幸福清风2 天前
【Python】基于Tkinter库实现文件夹拖拽与选择功能
windows·python·microsoft·tkinter
Leinwin2 天前
Azure Cobalt 100 VM:以卓越性能与能效优化云端工作负载
microsoft·azure
㏕追忆似水年华あ2 天前
逻辑600解析本03
python·flask
weixin_307779133 天前
在 Microsoft Azure 上部署 ClickHouse 数据仓库:托管服务与自行部署的全面指南
开发语言·数据库·数据仓库·云计算·azure