Skip to content

Commit

Permalink
重构实现
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwx committed Mar 6, 2020
1 parent 54b3cd5 commit 7a155a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea

39 changes: 39 additions & 0 deletions src/NeupassProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Wuwx\LaravelSocialiteNeupass;

use Illuminate\Support\Facades\Session;
use Laravel\Socialite\Contracts\Provider as ProviderContract;
use phpCAS;

class NeupassProvider implements ProviderContract
{
public function __construct()
{
session_set_save_handler(Session::getHandler());

phpCAS::client(CAS_VERSION_2_0, "pass.neu.edu.cn", 443, "tpass");

phpCAS::setNoCasServerValidation();
}

public function redirectUrl($url)
{
phpCAS::setFixedServiceURL($url);
return $this;
}

public function redirect()
{
return redirect(phpCAS::getServerLoginURL());
}

public function user()
{
phpCAS::forceAuthentication();
return (new User)->map([
'id' => phpCAS::getUser(),
'name' => phpCAS::getAttribute('USER_NAME'),
]);
}
}
21 changes: 1 addition & 20 deletions src/NeupassServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@ class NeupassServiceProvider extends ServiceProvider
public function boot()
{
Socialite::extend('neupass', function() {
return new class {
public function __construct()
{
phpCAS::client(CAS_VERSION_2_0, "pass.neu.edu.cn", 443, "tpass");
phpCAS::setNoCasServerValidation();
}
public function redirect()
{
phpCAS::setFixedServiceURL(phpCAS::getServiceURL() . "/callback");
return redirect(phpCAS::getServerLoginURL());
}
public function user()
{
phpCAS::forceAuthentication();
return (new User)->map([
'id' => phpCAS::getUser(),
'name' => phpCAS::getAttribute('USER_NAME'),
]);
}
};
return new NeupassProvider();
});
}

Expand Down

0 comments on commit 7a155a8

Please sign in to comment.