我要如何安全地整合並設定 Amazon Cognito 與外部 SAML 身分提供者?
2 分的閱讀內容
0
我想將 Amazon Cognito 使用者集區設定為使用來自外部 SAML 身分提供者 (IdP) 的加密 SAML 判斷提示。我希望我的應用程式的使用者驗證能夠安全。
解決方法
將 SAML IdP 新增到您的使用者集區
如果您沒有 Amazon Cognito 使用者集區,請參閱使用者集區入門。建立使用者集區後,在 IdP 端設定您的 SAML 應用程式。若要將 SAML IdP 新增至您的 Amazon Cognito 使用者集區,請參閱在使用者集區中新增和管理 SAML 身分提供者。
向您的 SAML IdP 提供加密憑證,以將加密的 SAML 判斷提示傳送至 Amazon Cognito
首先,從您的 Amazon Cognito 主控台下載加密憑證。然後,在您的 SAML IdP 的組態介面中,匯入加密憑證。有關如何匯入和啟動加密憑證的相關說明,請參閱您的 IdP 文件。例如,請參閱 Microsoft Learn 網站上的在 Microsoft Entra 管理中心設定權杖加密。
確認加密的 SAML 判斷提示流程
請完成下列步驟:
- 開啟瀏覽器的開發人員工具,然後建立 HTTP 封存 (HAR) 檔案。
- 前往您 Amazon Cognito 使用者集區的受管登入頁面。
- 選取 SAML IdP。Amazon Cognito 會將您重新導向至 IdP 的登入頁面。
- 在 HAR 檔案中,擷取您的 IdP 傳送至 saml2/idpresponse 端點的 SAML 判斷提示請求。
- 在您的瀏覽器中,查看 HAR 檔案中的 SAML 判斷提示回應。
包含加密 SAML 判斷提示的解碼後 SAML 回應範例:
<saml:EncryptedAssertion> <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element"> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/> <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <xenc:EncryptedKey> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/> <xenc:CipherData> <xenc:CipherValue> <!-- Encrypted key data --> hY7PK8L9eM+2Uw7....[abbreviated]....4nmB2gTfLwqX= </xenc:CipherValue> </xenc:CipherData> </xenc:EncryptedKey> </ds:KeyInfo> <xenc:CipherData> <xenc:CipherValue> <!-- Encrypted assertion data --> kB4urcHh7K5HHJ....[abbreviated]....8JpWGpfTj= </xenc:CipherValue> </xenc:CipherData> </xenc:EncryptedData> </saml:EncryptedAssertion>
未加密的解碼後 SAML 回應範例:
<saml:Assertion ID="ASRT#########" Version="2.0" IssueInstant="2024-07-10T10:00:00Z"> <saml:Issuer>https://idp.example.com/saml</saml:Issuer> <saml:Subject> <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"> USER123456789 </saml:NameID> <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"> <saml:SubjectConfirmationData NotOnOrAfter="2024-07-10T11:00:00Z" Recipient="https://app.example.com/saml/acs"/> </saml:SubjectConfirmation> </saml:Subject> <saml:Conditions NotBefore="2024-07-10T10:00:00Z" NotOnOrAfter="2024-07-10T11:00:00Z"> <saml:AudienceRestriction> <saml:Audience>https://app.example.com/saml</saml:Audience> </saml:AudienceRestriction> </saml:Conditions> <saml:AuthnStatement AuthnInstant="2024-07-10T10:00:00Z" SessionNotOnOrAfter="2024-07-10T18:00:00Z" SessionIndex="SESSION123456789"> <saml:AuthnContext> <saml:AuthnContextClassRef> urn:oasis:names:tc:SAML:2.0:ac:classes:Password </saml:AuthnContextClassRef> </saml:AuthnContext> </saml:AuthnStatement> <saml:AttributeStatement> <saml:Attribute Name="uid" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue>user123</saml:AttributeValue> </saml:Attribute> <saml:Attribute Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue>user@example.com</saml:AttributeValue> </saml:Attribute> <saml:Attribute Name="roles" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> <saml:AttributeValue>user</saml:AttributeValue> <saml:AttributeValue>admin</saml:AttributeValue> </saml:Attribute> </saml:AttributeStatement> </saml:Assertion>
**注意:**回應中的 saml:EncryptedAssertion 元素確認您已擁有加密的 SAML 判斷提示。只有您的 IdP 可以使用正確的私有金鑰解密並讀取判斷提示內容。如果回應中沒有 saml:EncryptedAssertion,則表示您有一個未加密的 SAML 判斷提示,該判斷提示會以明文形式顯示使用者和驗證詳細資訊。
相關資訊
- 語言
- 中文 (繁體)

AWS 官方已更新 3 個月前
沒有評論
相關內容
- 已提問 3 年前
- 已提問 2 年前