使用OAuth + SAML承载流进行身份验证(无效声明)

时间:2012-11-21 07:37:00

标签: single-sign-on saml

我正在尝试使用OAuth + SAML承载流进行身份验证(http://help.salesforce.com/help/doc/en/remoteaccess_oauth_SAML_bearer_flow.htm)

但我陷入了无效断言错误的地步:

{"error":"invalid_grant","error_description":"invalid assertion"}

这是我的断言:

<?xml version="1.0"?>
  <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="C625490D-C2B9-15BE-6DFA-7286288D9655" IssueInstant="2012-04-04T06:54:14Z" Version="2.0">
    <saml:Issuer>3MVG9Y6d_Btp4.....d0jnN</saml:Issuer>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
      <ds:SignedInfo>
        <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
        <ds:Reference URI="#C625490D-C2B9-15BE-6DFA-7286288D9655">
          <ds:Transforms>
            <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
            <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
          </ds:Transforms>
          <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
          <ds:DigestValue>f187DeCiwFhhH2etlU+5byskey4=</ds:DigestValue>
        </ds:Reference>
      </ds:SignedInfo>
      <ds:SignatureValue>
MIID6zCCAtOgAwI...........4qbvd3sxAQmkhR98FSsQixMI+bTHq9zRgeFu6W5GWsun3tmqNE=
</ds:SignatureValue>
    </ds:Signature>
    <saml:Subject>
      <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">org2@dot.com
      </saml:NameID>
      <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
        <saml:SubjectConfirmationData Recipient="https://login.salesforce.com/services/oauth2/token" NotOnOrAfter="2012-11-20T06:35:42Z"/>
      </saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2012-11-19T06:34:42Z" NotOnOrAfter="2012-11-20T06:35:42Z">
      <saml:AudienceRestriction>
        <saml:Audience>https://login.salesforce.com/services/oauth2/token</saml:Audience>
      </saml:AudienceRestriction>
    </saml:Conditions>
    <saml:AuthnStatement AuthnInstant="2012-11-20T06:35:42Z" SessionIndex="ED868FE5-841D-5192-766C-941A60D6602F">
      <saml:AuthnContext>
        <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml:AuthnContextClassRef>
      </saml:AuthnContext>
    </saml:AuthnStatement>
  </saml:Assertion>

以下是我提出请求的方式:

curl https://login.salesforce.com/services/oauth2/token -H "Content-Type='application/x-www-form-urlencoded'" -d "grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer" -d "assertion=`cat saml-assertion.base64`"

我已经将断言正确地编码为base64url(之前我收到了关于断言中无效字符的错误,我已经修复了)

请告诉我什么/我可以在哪里进一步查看,以了解为什么我的断言无效! PS:所有内容都是从url的示例断言中复制出来的,并且我更改了用户名,颁发者和证书。另外,我将NotBefore设置为用户的确切登录时间。

1 个答案:

答案 0 :(得分:-1)

当您发送格式类型值时,也需要对格式类型值进行编码。 瓮%3Aietf%3Aparams%3Aoauth%3Agrant型%3Asaml2承载

Saml断言需要单一断言。它需要像你一样进行Base64编码,然后再次删除填充或urlencode。

  

“断言”参数的值必须包含单个SAML 2.0   断言。 SAML断言XML数据必须使用
进行编码   base64url,其中编码符合第5节中的定义   RFC 4648 [RFC4648]并且填充位设置为零。至   避免需要后续的编码步骤(通过“application /
  x-www-form-urlencoded“[W3C.REC-html401-19991224],例如),
  base64url编码的数据不应该是换行和填充字符
  (“=”)不应包括在内。

http://tools.ietf.org/html/draft-ietf-oauth-saml2-bearer-17#section-2.1

使用帖子编码值发送:

grant_type =瓮%3Aietf%3Aparams%3Aoauth%3Agrant型%3Asaml2承载&安培;  断言= PHNhbWxwOl ... [省略] ... ZT4