| 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\Protocols\HTTPResponse; |
| 26: | use SimpleID\Crypt\Random; |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | class OAuthDynamicClient extends OAuthClient { |
| 32: | |
| 33: | protected $dynamic = true; |
| 34: | |
| 35: | public function __construct($data = []) { |
| 36: | parent::__construct($data); |
| 37: | |
| 38: | $rand = new Random(); |
| 39: | $this->cid = '_' . $rand->id() . '.oauth'; |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public function fetchJWKs() { |
| 48: | if (isset($this->container['oauth']['jwks_uri'])) { |
| 49: | $web = \Web::instance(); |
| 50: | |
| 51: | $response = new HTTPResponse($web->request($this->container['oauth']['jwks_uri'], [ 'headers' => [ 'Accept' => 'application/jwk-set+json,application/json,text/plain,application/octet-stream' ] ])); |
| 52: | if ($response->isHttpError()) return; |
| 53: | |
| 54: | $jwks = json_decode($response->getBody(), true); |
| 55: | if ($jwks == NULL) return; |
| 56: | |
| 57: | $this->container['oauth']['jwks'] = $jwks; |
| 58: | } |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | public function getDynamicClientInfo() { |
| 67: | $results = array_merge($this->container['oauth'], [ |
| 68: | 'client_id' => $this->getStoreID() |
| 69: | ]); |
| 70: | |
| 71: | |
| 72: | if (isset($results['jwk_uri'])) unset($results['jwks']); |
| 73: | |
| 74: | return $results; |
| 75: | } |
| 76: | } |
| 77: | |
| 78: | ?> |