Android / iOS:如何使用SAML协议为Azure AD提供移动设备的SSO

问题描述 投票:1回答:1

我正在尝试使用SAML 2.0协议在Azure AD中在移动本机设备中实现SSO。从网上我可以成功登录,但我找不到使用移动客户端做同样的方法。我尝试使用Microsoft Azure here提供的Android项目。我能够使用这个项目获得令牌。但我不明白接下来需要做什么。我们之前的请求是这样的(没有Azure):https://myssodomain.com/adfs/ls/?SAMLRequest=SomeCodehere。对此请求的调用用于给我一个SAMLResponse,我在重定向URL中使用它,作为回报,它曾用于向我提供用户个人资料详细信息。现在,就像在Azure中一样,机制完全不同,我不明白在收到访问令牌后我该怎么办。我应该如何调用上面的URL来获取SAMLResponse代码,以便我可以使用is从服务提供者获取用户配置文件。

azure-active-directory single-sign-on saml-2.0
1个回答
0
投票

下面的协议图描述了单点登录序列。云服务(服务提供者)使用HTTP重定向绑定将AuthnRequest(身份验证请求)元素传递给Azure AD(身份提供者)。然后,Azure AD使用HTTP post绑定将Response元素发布到云服务。

enter image description here

要请求用户身份验证,云服务会向Azure AD发送AuthnRequest元素。示例SAML 2.0 AuthnRequest可能类似于以下示例:

<samlp:AuthnRequest
xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
ID="id6c1c178c166d486687be4aaf5e482730"
Version="2.0" IssueInstant="2013-03-18T03:28:54.1839884Z"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">https://www.contoso.com</Issuer>
</samlp:AuthnRequest>

当请求的登录成功完成后,Azure AD会向云服务发布响应。对成功登录尝试的响应如下所示:

<samlp:Response ID="_a4958bfd-e107-4e67-b06d-0d85ade2e76a" Version="2.0" IssueInstant="2013-03-18T07:38:15.144Z" Destination="https://contoso.com/identity/inboundsso.aspx" InResponseTo="id758d0ef385634593a77bdf7e632984b6" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion"> https://login.microsoftonline.com/82869000-6ad1-48f0-8171-272ed18796e9/</Issuer>
  <ds:Signature xmlns:ds="https://www.w3.org/2000/09/xmldsig#">
    ...
  </ds:Signature>
  <samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
  </samlp:Status>
  <Assertion ID="_bf9c623d-cc20-407a-9a59-c2d0aee84d12" IssueInstant="2013-03-18T07:38:15.144Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
    <Issuer>https://login.microsoftonline.com/82869000-6ad1-48f0-8171-272ed18796e9/</Issuer>
    <ds:Signature xmlns:ds="https://www.w3.org/2000/09/xmldsig#">
      ...
    </ds:Signature>
    <Subject>
      <NameID>Uz2Pqz1X7pxe4XLWxV9KJQ+n59d573SepSAkuYKSde8=</NameID>
      <SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
        <SubjectConfirmationData InResponseTo="id758d0ef385634593a77bdf7e632984b6" NotOnOrAfter="2013-03-18T07:43:15.144Z" Recipient="https://contoso.com/identity/inboundsso.aspx" />
      </SubjectConfirmation>
    </Subject>
    <Conditions NotBefore="2013-03-18T07:38:15.128Z" NotOnOrAfter="2013-03-18T08:48:15.128Z">
      <AudienceRestriction>
        <Audience>https://www.contoso.com</Audience>
      </AudienceRestriction>
    </Conditions>
    <AttributeStatement>
      <Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name">
        <AttributeValue>[email protected]</AttributeValue>
      </Attribute>
      <Attribute Name="http://schemas.microsoft.com/identity/claims/objectidentifier">
        <AttributeValue>3F2504E0-4F89-11D3-9A0C-0305E82C3301</AttributeValue>
      </Attribute>
      ...
    </AttributeStatement>
    <AuthnStatement AuthnInstant="2013-03-18T07:33:56.000Z" SessionIndex="_bf9c623d-cc20-407a-9a59-c2d0aee84d12">
      <AuthnContext>
        <AuthnContextClassRef> urn:oasis:names:tc:SAML:2.0:ac:classes:Password</AuthnContextClassRef>
      </AuthnContext>
    </AuthnStatement>
  </Assertion>
</samlp:Response>

Response元素包括授权请求的结果。 Azure AD在Response元素中设置ID,Version和IssueInstant值。它还设置以下属性:

•目标:登录成功完成后,将其设置为服务提供商的RedirectUri(云服务)。

•InResponseTo:设置为启动响应的AuthnRequest元素的ID属性。

有关进一步的文档,您可以参考以下主题

https://docs.microsoft.com/en-us/azure/active-directory/develop/single-sign-on-saml-protocol https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-saml-protocol-reference

SAML协议要求身份提供程序(Azure AD)和服务提供程序(应用程序)交换有关自身的信息。

//执行身份验证请求mAuthContext.acquireToken(getActivity(),RESOURCE_ID,CLIENT_ID,REDIRECT_URI, PromptBehavior.Auto,getAuthInteractiveCallback());

// ...

//获取令牌以调用API,如Microsoft Graph mAuthResult.getAccessToken()

获得令牌后,您可以使用它来调用图API。

这里我们有一个用于在android中设置SSO的wiki,您可能会感兴趣。

https://github.com/AzureAD/azure-activedirectory-library-for-android/wiki

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.