cas 单点登录 php扩展,thinkcmf集成phpCAS单点登录客户端

一、搭建服务端

二、导入phpCAS依赖

在thinkCMF项目根目录下的composer.json文件中添加"apereo/phpcas": "^1.3.7"

composer.json文件示例:{

"name": "thinkcmf/thinkcmf",

"description": "ThinkCMF based on ThinkPHP 5.0 , it is a free and open source Content Management Framework(CMF)",

"type": "project",

"keywords": [

"cmf",

"thinkcmf",

"framework",

"thinkphp",

"ORM"

],

"homepage": "http://www.thinkcmf.com/",

"license": "Apache-2.0",

"authors": [

{

"name": "thinkcmf",

"email": "zxxjjforever@163.com"

}

],

"require": {

"php": ">=5.4.0",

"ext-json": "*",

"topthink/framework": "~5.0.0",

"topthink/think-helper": "^1.0",

"topthink/think-captcha": "^1.0",

"phpmailer/phpmailer": "^5.2",

"mindplay/annotations": "^1.3",

"topthink/think-image": "^1.0",

"ezyang/htmlpurifier": "^4.9",

"topthink/think-queue": "^1.1.4",

"electrolinux/phpquery": "^0.9.6",

"apereo/phpcas": "^1.3.7"

},

"extra": {

"think-path": "simplewind/thinkphp"

},

"config": {

"vendor-dir": "simplewind/vendor"

},

"repositories": {

"packagist": {

"type": "composer",

"url": "https://packagist.phpcomposer.com"

}

}

}

导入依赖完成后目录:

4b73b9bb7030758896dde413cf23cb3e.png

注意:如果是http访问需要修改CAS/client.php文件中的317行https修改为http

426ab20d60a5ebe54400fa7602c0df6d.png

三、新建cas应用

在app目录下新建cas应用目录如:

1d115fed1c4042b54a721364d94a8f9a.png

IndexController 类中的代码<?php

namespace app\cas\controller;

use cmf\controller\HomeBaseController;

use phpCAS;

class IndexController extends HomeBaseController

{

public function index()

{

phpCAS::setDebug();

// Enable verbose error messages. Disable in production!

phpCAS::setVerbose(true);

// Initialize phpCAS

phpCAS::client(CAS_VERSION_2_0, "localhost", 8443, "cas");

// For production use set the CA certificate that is the issuer of the cert

// on the CAS server and uncomment the line below

// phpCAS::setCasServerCACert($cas_server_ca_cert_path);

// For quick testing you can disable SSL validation of the CAS server.

// THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.

// VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!

phpCAS::setNoCasServerValidation();

// force CAS authentication

phpCAS::forceAuthentication();

// at this step, the user has been authenticated by the CAS server

// and the user's login name can be read with phpCAS::getUser().

// logout if desired

if (isset($_REQUEST['logout'])) {

phpCAS::logout();

}

echo phpCAS::getVersion();

$this->assign("user", phpCAS::getUser());

$this->fetch();

}

}

四:访问thinkcas是你自己的项目名称

8d081f67b1840225d8568e279df8af27.png

输入用户名/密码:casuser::Mellon

登录成功后:显示phpCAS的版本号1.3.7

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值