Code Monkey home page Code Monkey logo

sso's Introduction

sso login

composer

composer require wangjingchun/sso

composer.json

"require": { "wangjingchun/sso": "^0.1.0" }

参数

  1. $server_url,server同步登陆的请求地址
  2. $broker_id,调用方站点的id
  3. $broker_secret,调用方站点的secret

方法

  1. getUserInfo(),获取用户登陆信息
  2. login($username, $password),用户登陆,参数为用户名和密码
  3. logout(),退出登陆

例子程序

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use wangjingchun\sso\MySso;

class TestController extends Controller
{
	public $server_url = 'http://homestead.app/web/wjc/ssoserver';
	public $broker_id = 'Alice';
	public $broker_secret = '8iwzik1bwd';

	public function index()
	{
		$mySso = new MySso($this->server_url, $this->broker_id, $this->broker_secret);

		try {
		    $user = $mySso->getUserInfo();
		} catch (NotAttachedException $e) {
		    header('Location: ' . $_SERVER['REQUEST_URI']);
		    exit;
		} catch (SsoException $e) {
		    header("Location: " . url('sso/error') . "?sso_error=" . $e->getMessage(), true, 307);
		}

		if (!$user) {
		    header("Location: " . url('test/login'), true, 307);
		    exit;
		} else {
			echo 'username->' . $user['username'] . '<br>';
			echo 'fullname->' . $user['fullname'] . '<br>';
			echo 'email->' . $user['email'] . '<br><br>';

			echo '<a href="' . url('test/logout') . '">logout</a>';
		}
	}

	public function login()
	{
		return view('test.login');
	}

	public function postlogin(Request $request)
	{
		$username = $request->input('username');
		$password = $request->input('password');

		$mySso = new MySso($this->server_url, $this->broker_id, $this->broker_secret);

		if ($mySso->getUserInfo() || $mySso->login($username, $password)) {
			header("Location: " . URL('test/index'), true, 303);
        	exit;
		}
	}

	public function logout()
	{
		$mySso = new MySso($this->server_url, $this->broker_id, $this->broker_secret);

		$mySso->logout();
		header("Location: " . URL('test/index'), true, 303);
        	exit;
	}

	public function error(Request $request)
	{
		$sso_error = $request->input('sso_error');

		echo $sso_error;
	}
}


?>

sso's People

Contributors

wangjingchun avatar

Stargazers

Ithoq Projosasmito avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.