SimpleSAMLphp 生成断言

SimpleSAMLphp generate assertion

我正在使用 SimpleSAMLphp 作为我们拥有的一堆应用程序的 IdP,主要是 Drupal 站点。我在 IdP 上使用 SQL 作为 authsource 并且可以验证用户身份,响应 returns 到 Drupal 并且用户已通过身份验证.一切顺利!

但是我们还需要使用社交登录(使用 Twitter、Facebook 等登录)。 SimpleSAMLphp 支持 OAuth,我已经设置好并且登录在 IdP 上与社交帐户,SimpleSAML 创建会话和 cookie,但我没有在 Drupal 站点上进行身份验证。

我需要做的是通过返回到 Drupal 并在那里验证用户来完成请求,也就是说,在成功时向 Drupal 发出断言。

就像在 SQL 源中一样,我已经在每个源文件(Twitter.php、Facebook.php 等)中映射了属性,但是 SQL auth returns 到 Drupal 并创建一个会话,其他的只是在模板中显示它们的属性。

如何从这些社交登录中为 Drupal 生成并发回断言,以便在那里验证我的用户?

saml10-sp-remote.php (IdP)

$metadata['https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/metadata.php/sp'] = array (
  'SingleLogoutService' =>
  array (
    0 =>
    array (
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml2-logout.php/sp',
    ),
    1 =>
    array (
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml2-logout.php/sp',
    ),
  ),
  'AssertionConsumerService' =>
  array (
    0 =>
    array (
      'index' => 0,
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml2-acs.php/sp',
    ),
    1 =>
    array (
      'index' => 1,
      'Binding' => 'urn:oasis:names:tc:SAML:1.0:profiles:browser-post',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml1-acs.php/sp',
    ),
    2 =>
    array (
      'index' => 2,
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml2-acs.php/sp',
    ),
    3 =>
    array (
      'index' => 3,
      'Binding' => 'urn:oasis:names:tc:SAML:1.0:profiles:artifact-01',
      'Location' => 'https://durpal_url/simplesaml_drupal_sp/module.php/saml/sp/saml1-acs.php/sp/artifact',
    ),
  ),
  'certData' => 'xxxx',
);

authsources.php (IdP)

'sql' => array(
        'sqlauth:SQL',
        'dsn' => 'mysql:host=localhost;dbname=db',
        'username' => 'user',
        'password' => 'pass',
        'query' => 'SELECT u.uid, u.name, u.mail, r.name AS role FROM users u JOIN users_roles ur on ur.uid = u.uid JOIN role r on r.rid = ur.rid where u.mail = :username AND pass = MD5(:password);',
    ),

'facebook' => array(
    'authfacebook:Facebook',
    'api_key' => 'xxxx',
    'secret' => 'xxxx',
    'req_perms' => 'email',
),

'linkedin' => array(
    'authlinkedin:LinkedIn',
    'key' => 'xxxx',
    'secret' => 'xxxx',
),

'twitter' => array(
    'authtwitter:Twitter',
    'key' => 'xxxx',
    'secret' => 'xxxx',
    'force_login' => true,
),

saml20-idp-remote.php (SP, Drupal)

$metadata['http://idp_url/simplesaml/saml2/idp/metadata.php'] = array (
  'metadata-set' => 'saml20-idp-remote',
  'entityid' => 'http://idp_url/simplesaml/saml2/idp/metadata.php',
  'SingleSignOnService' =>
  array (
    0 =>
    array (
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
      'Location' => 'http://idp_url/simplesaml/saml2/idp/SSOService.php',
    ),
  ),
  'SingleLogoutService' =>
  array (
    0 =>
    array (
      'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
      'Location' => 'http://idp_url/simplesaml/saml2/idp/SingleLogoutService.php',
    ),
  ),
  'certData' => 'xxx',
  'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
);

saml20-idp-hosted.php (IdP)

$metadata['__DYNAMIC:1__'] = array(
    'host' => '__DEFAULT__',
    'privatekey' => 'mysite.com.key',
    'certificate' => 'mysite.com.crt',
    'auth' => 'sql',
);

背景

您的问题是您的身份提供者配置为使用 sql 身份验证,而不是 twitter、linkedin 等。drupal 站点会将您发送给 IDP,而 IDP 只知道 sql.虽然您确实为社交配置了 authsources,但 SSP 允许您独立于 IDP 配置测试和验证这些。这就是为什么 SSP 只是在模板中显示社交属性,而不是让您使用它们登录 drupal。

选项 A

multiauth 将让您定义一个 authsource,其中包括您的社交和 sql。然后您配置您的 idp 以使用新的 multiauth authsource

选项 B

每个社会提供者一个 IDP。我们 运行 每个社会提供者一个 IDP。我们在 saml20-idp-hosted.php 中定义了多个 IDP(具有唯一的实体 ID)——每个社交帐户一个。我们这样做是因为我们的每个 SP 只想信任所有配置的社交 IDP 的一个子集。

此选项中的每个 SP 都将在 saml20-idp-remote.php

中包含额外的 IDP 数据

选项 C

外包。我们 运行 将这种社交 saml 网关作为 SaaS product。如果您不喜欢 运行 自己的东西,或者如果您有多个 SP 都需要不同的社交提供者,或者每个 SP 使用不同的社交 api keys/secrets,那么这是有道理的。