| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | namespace SimpleID\Protocols\Connect; |
| 24: | |
| 25: | use Psr\Log\LogLevel; |
| 26: | use SimpleID\Module; |
| 27: | use SimpleID\ModuleManager; |
| 28: | use SimpleID\Auth\AuthManager; |
| 29: | use SimpleID\Base\RouteContentNegotiationEvent; |
| 30: | use SimpleID\Base\ScopeInfoCollectionEvent; |
| 31: | use SimpleID\Store\StoreManager; |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | class OpenID2MigrationModule extends Module { |
| 40: | |
| 41: | public function __construct() { |
| 42: | parent::__construct(); |
| 43: | |
| 44: | $mgr = ModuleManager::instance(); |
| 45: | $mgr->loadModule('SimpleID\Protocols\Connect\ConnectModule'); |
| 46: | } |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | public function onRouteContentNegotiationEvent(RouteContentNegotiationEvent $event) { |
| 52: | if ($event->getRoute() != 'user') return; |
| 53: | |
| 54: | $content_type = $event->negotiate([ 'text/html', 'application/xml', 'application/xhtml+xml', 'application/json' ]); |
| 55: | |
| 56: | if ($content_type == 'application/json') { |
| 57: | $this->userJSON(); |
| 58: | $event->stopPropagation(); |
| 59: | } |
| 60: | } |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public function userJSON() { |
| 69: | $mgr = ModuleManager::instance(); |
| 70: | |
| 71: | |
| 72: | $connect_module = $mgr->getModule('SimpleID\Protocols\Connect\ConnectModule'); |
| 73: | $iss = $connect_module->getCanonicalHost(); |
| 74: | $store = StoreManager::instance(); |
| 75: | $user = $store->loadUser($this->f3->get('PARAMS.uid')); |
| 76: | |
| 77: | if ($user != NULL) { |
| 78: | header('Content-Type: application/json'); |
| 79: | print json_encode([ 'iss' => $iss ]); |
| 80: | } else { |
| 81: | $this->fatalError($this->f3->get('intl.common.user_not_found', $this->f3->get('PARAMS.uid')), 404); |
| 82: | } |
| 83: | } |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | public function onConnectBuildClaimsEvent(ConnectBuildClaimsEvent $event) { |
| 90: | $context = $event->getContext(); |
| 91: | $scope = $event->getScope(); |
| 92: | $user = $event->getUser(); |
| 93: | |
| 94: | if (($context == 'id_token') && in_array('openid2', $scope)) { |
| 95: | if (isset($user['openid']['identity'])) { |
| 96: | $event->addResult([ 'openid2_id' => $user['openid']['identity'] ]); |
| 97: | } |
| 98: | } |
| 99: | } |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | public function onScopeInfoCollectionEvent(ScopeInfoCollectionEvent $event) { |
| 106: | $event->addScopeInfo('oauth', [ |
| 107: | 'openid2' => [ |
| 108: | 'description' => $this->f3->get('intl.core.connect.scope.openid2'), |
| 109: | 'claims' => [ 'openid2_id' ], |
| 110: | 'weight' => -1 |
| 111: | ] |
| 112: | ]); |
| 113: | } |
| 114: | } |
| 115: | ?> |
| 116: | |