| 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\OAuth; |
| 24: | |
| 25: | use SimpleID\Models\Client; |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | class OAuthClient extends Client { |
| 31: | |
| 32: | protected $dynamic = false; |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | public function __construct($data) { |
| 40: | parent::__construct(array_replace_recursive([ |
| 41: | 'oauth' => [ |
| 42: | 'token_endpoint_auth_method' => 'client_secret_basic', |
| 43: | 'response_types' => [ 'code' ], |
| 44: | 'grant_types' => [ 'authorization_code' ], |
| 45: | 'application_type' => 'web' |
| 46: | ] |
| 47: | ], $data)); |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | public function isConfidential() { |
| 61: | if (isset($this->container['oauth']['token_endpoint_auth_method']) |
| 62: | && ($this->container['oauth']['token_endpoint_auth_method'] == 'none')) |
| 63: | return false; |
| 64: | |
| 65: | return (isset($this->container['oauth']['client_secret'])); |
| 66: | } |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | public function isNative() { |
| 76: | return (isset($this->container['oauth']['application_type'])) ? ($this->container['oauth']['application_type'] == 'native') : false; |
| 77: | } |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | public function hasRedirectUri($redirect_uri) { |
| 90: | $redirect_uri_found = false; |
| 91: | |
| 92: | $is_native = $this->isNative(); |
| 93: | |
| 94: | $redirect_uri_components = parse_url($redirect_uri); |
| 95: | if ($redirect_uri_components == false) return false; |
| 96: | |
| 97: | foreach ($this->container['oauth']['redirect_uris'] as $client_redirect_uri) { |
| 98: | $client_redirect_uri_components = parse_url($client_redirect_uri); |
| 99: | if (($client_redirect_uri_components == false) |
| 100: | || !isset($client_redirect_uri_components['scheme']) |
| 101: | || !isset($client_redirect_uri_components['host'])) continue; |
| 102: | |
| 103: | |
| 104: | |
| 105: | if (!isset($client_redirect_uri_components['query']) && isset($redirect_uri_components['query'])) continue; |
| 106: | |
| 107: | if ($is_native && (strtolower($client_redirect_uri_components['scheme']) == 'http') |
| 108: | && (($client_redirect_uri_components['host'] == '127.0.0.1') || ($client_redirect_uri_components['host'] == '[::1]'))) { |
| 109: | |
| 110: | |
| 111: | $request_redirect_uri = preg_replace('!(http://(127\.0\.0\.1|\[::1\]))(:\d+)?!', '$1', $redirect_uri); |
| 112: | } else { |
| 113: | $request_redirect_uri = $redirect_uri; |
| 114: | } |
| 115: | |
| 116: | if (strcasecmp(substr($request_redirect_uri, 0, strlen($client_redirect_uri)), $client_redirect_uri) === 0) { |
| 117: | $redirect_uri_found = true; |
| 118: | break; |
| 119: | } |
| 120: | } |
| 121: | |
| 122: | return $redirect_uri_found; |
| 123: | } |
| 124: | } |
| 125: | |
| 126: | ?> |