开放ID实施PowerSchool PHP

时间:2018-03-07 07:35:39

标签: php openid lightopenid powerschool

我查看了有关OpenID实施的PowerSchool的文档。但是,我认为它错过了重要信息,即我们如何传递所需的属性。我已经研究了其他platforms中的示例实现。但是,它们似乎与文档所讨论的不同。

在这种情况下,如何在PHP中实现PowerSchool的Open ID。经过多次努力,我已经有第三方站点成功执行握手,但是,没有检索到任何属性值,也没有错误,即使在日志中也没有。

1 个答案:

答案 0 :(得分:0)

PowerSchool的Open ID SSO(单点登录)目前仅在从PowerSchool网站发起请求时才有效。因此,首先要创建Open ID链接插件。

SSO链接插件

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://plugin.powerschool.pearson.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation='http://plugin.powerschool.pearson.com plugin.xsd'
    name="Insert Your PluginsName"
    version="1.0.0"
    description="Insert a description here">
    <!-- The host name without scheme i.e., https. This is the host with which PowerSchool will perform the handshake -->
    <!-- and will pass the attributes to. -->
    <!-- NOTE: This host must have a valid SSL for this to work. -->
    <openid host="www.myopenid.com">
        <links>
            <link display-text="Insert links display text here"
                  title="Insert links title here"
                  path="/openidlogin">
                <!-- The relative path to the hostname Open ID initiation is performed on the host specified above i.e., -->
                <!-- www.myopenid.com/openidlogin -->
                <ui_contexts>
                    <!-- You may add other user contexts too i.e., guardian etc -->
                    <ui_context id="admin.header" />
                    <ui_context id="admin.left_nav" />
                </ui_contexts>
            </link>
        </links>
    </openid>
    <publisher name="XYZ">
        <contact email="xyzAtmyopenId.com"/>
    </publisher>
</plugin>
  1. 将上述内容另存为XML文件。
  2. 转到管理网站,即xyzps.com/admin/home.html
  3. 导航至系统 - &gt;系统设置 - &gt;插件管理配置 - &gt;安装 - &gt;安装插件 - &gt;启用插件。
  4. 该插件现在应该在ui_contexts中提供的上下文中可见,即Admin标题和左侧导航。
  5. LightOpenID

    转到LightOpenID并将其添加到您的项目中。

    使用PowerSchool和属性请求进行身份验证

    在openid主机插件中提到的路径上,即/openidlogin添加所需的属性并重定向到身份验证网址:

    $openid = new LightOpenID("Insert hostname i.e., www.myopenid.com");
    
    $openid->identity = $_GET['openid_identifier'];
    
    $openid->required = array(
        'email'=>'http://powerschool.com/entity/email'
    );
    
    $openid->returnUrl = 'Insert SSL enabled hostname i.e., https://www.myopenid.com/authenticateopenid';
    
    header('Location: ' . $openid->authUrl());
    

    自定义LightOpenID

    在继续之前,我们需要修改LightOpenID,因为它在属性前加http://axschema.org/,因此不会返回任何属性值。要做到这一点:

    1. 导航至LightOpenID.php - &gt; axParams()并更改

      $this->aliases[$alias] = 'http://axschema.org/' . $field;
      

      $this->aliases[$alias] = $field;
      
    2. 导航至LightOpenID.php - &gt; getAxAttributes()并更改

      $key = substr($this->getItem($prefix . '_type_' . $key), $length);
      

      $key = $this->getItem($prefix . '_type_' . $key);
      
    3. 验证并检索用户的属性

      在Open ID的返回网址中指定的路径,即authenticateopenid,验证用户并检索其属性:

      $openid = new LightOpenID("Insert hostname i.e., www.myopenid.com");
      
      if ($openid->mode)
      {
          if ($openid->mode == 'cancel') {
              echo "User has canceled authentication !";
          } elseif ($openid->validate()) {
      
              $data = $openid->getAttributes();
              $email = $data['http://powerschool.com/entity/email'];
              echo "</br>Email: " . $email . "</br>";
      
          }
           else {
              echo "The user has not logged in";
          }
      }
      else {
          echo "Go to PowerSchool to log in.";
      }