Page MenuHomePhabricator

D653.diff
No OneTemporary

D653.diff

diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -16,8 +16,17 @@
}
},
+ "scripts": {
+ "test": [
+ "./vendor/bin/phpstan analyse ./src --level 7"
+ ]
+ },
+
"require": {
"magic3w/url-reflection": "dev-master",
- "spitfire/request": "dev-master"
+ "spitfire/request": "^0.1.1"
+ },
+ "require-dev": {
+ "phpstan/phpstan": "^0.12.82"
}
}
diff --git a/composer.lock b/composer.lock
--- a/composer.lock
+++ b/composer.lock
@@ -4,19 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "997205af2fab313d28388c068c3706de",
+ "content-hash": "4f87e91c3e74db4752cf1faa2b5b49e7",
"packages": [
{
"name": "magic3w/url-reflection",
- "version": "v0.1.0",
+ "version": "dev-master",
"source": {
"type": "git",
"url": "https://phabricator.magic3w.com/source/url-reflection.git",
- "reference": "23bcb67767893f9225befba28cfc3aba30bf1b43"
+ "reference": "341d1ede12d28159101b77c8ae12b544dba15a8c"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
},
+ "default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
@@ -34,18 +35,18 @@
}
],
"description": "Allows applications to have a URL parsed and retrieve information about it's components",
- "time": "2020-09-11T13:26:04+00:00"
+ "time": "2021-02-11T13:17:34+00:00"
},
{
"name": "spitfire/request",
- "version": "v0.1.0",
+ "version": "v0.1.1",
"source": {
"type": "git",
- "url": "https://phabricator.magic3w.com/source/spitifire-request.git",
- "reference": "d3b3801273b7d65f42e974834a0658d9255caacd"
+ "url": "https://phabricator.magic3w.com/source/spitfire-request.git",
+ "reference": "0e8166d802e0e71dd12365bca0215043c9df37d2"
},
"require": {
- "magic3w/url-reflection": "^0.1.0"
+ "magic3w/url-reflection": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^9.4"
@@ -67,13 +68,76 @@
}
],
"description": "Spitfire request mechanism",
- "time": "2020-10-15T16:00:20+00:00"
+ "time": "2021-01-21T07:59:55+00:00"
+ }
+ ],
+ "packages-dev": [
+ {
+ "name": "phpstan/phpstan",
+ "version": "0.12.82",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan.git",
+ "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3920f0fb0aff39263d3a4cb0bca120a67a1a6a11",
+ "reference": "3920f0fb0aff39263d3a4cb0bca120a67a1a6a11",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1|^8.0"
+ },
+ "conflict": {
+ "phpstan/phpstan-shim": "*"
+ },
+ "bin": [
+ "phpstan",
+ "phpstan.phar"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.12-dev"
+ }
+ },
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan - PHP Static Analysis Tool",
+ "support": {
+ "issues": "https://github.com/phpstan/phpstan/issues",
+ "source": "https://github.com/phpstan/phpstan/tree/0.12.82"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/ondrejmirtes",
+ "type": "github"
+ },
+ {
+ "url": "https://www.patreon.com/phpstan",
+ "type": "patreon"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-03-19T06:08:17+00:00"
}
],
- "packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": [],
+ "stability-flags": {
+ "magic3w/url-reflection": 20
+ },
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
diff --git a/src/SSO.php b/src/SSO.php
--- a/src/SSO.php
+++ b/src/SSO.php
@@ -100,7 +100,7 @@
*/
public function credentials($audience = null)
{
- $request = URLReflection::fromURL(sprintf('%s/token/create.json', $this->endpoint));
+ $request = new Request(URLReflection::fromURL(sprintf('%s/token/create.json', $this->endpoint)));
$request->post('type', 'client_credentials');
$request->post('client', $this->sso->getAppId());
$request->post('secret', $this->sso->getSecret());
diff --git a/src/Scope.php b/src/Scope.php
--- a/src/Scope.php
+++ b/src/Scope.php
@@ -29,7 +29,6 @@
class Scope
{
- private $sso;
private $app;
private $id;
private $exists = null;
@@ -37,12 +36,11 @@
/**
*
- * @param SSO $sso
* @param App $app
* @param string $id
*/
- public function __construct($sso, $app, $id) {
- $this->sso = $sso;
+ public function __construct(App $app, string $id)
+ {
$this->app = $app;
$this->id = $id;
}
diff --git a/src/Token.php b/src/Token.php
--- a/src/Token.php
+++ b/src/Token.php
@@ -1,38 +1,73 @@
<?php namespace magic3w\phpauth\sdk;
use Exception;
+use spitfire\io\request\Request;
class Token
{
+ /**
+ *
+ * @var SSO
+ */
private $sso;
+
+ /**
+ *
+ * @var string
+ */
private $token;
+
+ /**
+ *
+ * @var int
+ */
private $expires;
- public function __construct($sso, $token, $expires) {
+ /**
+ *
+ * @param SSO $sso
+ * @param string $token
+ * @param int $expires
+ */
+ public function __construct(SSO $sso, string $token, int $expires)
+ {
$this->sso = $sso;
$this->token = $token;
$this->expires = $expires;
}
+ /**
+ * Returns the token's ID
+ *
+ * @return string
+ */
public function getId() {
return $this->token;
}
+ /**
+ *
+ * @deprecated since v0.1.1 (20210331)
+ * @return mixed
+ */
public function getTokenInfo() {
static $cache = null;
if ($cache !== null) { return $cache; }
- $response = file_get_contents($this->sso->getEndpoint() . '/auth/index/' . $this->token . '.json');
-
- if (!isset($http_response_header)) { throw new Exception('SSO connection failed'); }
- if (!strstr($http_response_header[0], '200')) { throw new Exception('SSO error'); }
+ $request = new Request($this->sso->getEndpoint() . '/auth/index/' . $this->token . '.json');
+ $response = $request->send()->expect(200)->json();
- return $cache = json_decode($response);
+ return $cache = $response;
}
+ /**
+ * Indicates whether the token is still valid.
+ *
+ * @return bool
+ */
public function isAuthenticated() {
- return $this->getTokenInfo()->authenticated;
+ return $this->expires > time();
}
}
diff --git a/src/User.php b/src/User.php
--- a/src/User.php
+++ b/src/User.php
@@ -5,57 +5,113 @@
class User
{
+ /**
+ * @var int
+ */
private $id;
+
+ /**
+ * The current (and therefore canonical) username for this account.
+ *
+ * @var string
+ */
private $username;
+
+ /**
+ * A list of known aliases that the user has had.
+ *
+ * @var string[]
+ */
private $aliases;
+
+ /**
+ * A list of groups the user is a part of. Auth groups provide the user with certain authority.
+ *
+ * @var string[]
+ */
private $groups;
+
+ /**
+ * Indicates whether the user confirmed their account using an email address.
+ *
+ * @var bool
+ */
private $verified;
+
+ /**
+ * Timestamp of the user's sign up.
+ *
+ * @var int
+ */
private $registered;
- private $attributes;
+
+ /**
+ *
+ * @var object
+ */
private $avatar;
- public function __construct($id, $username, $aliases, $groups, $verified, $registered, $attributes, $avatar) {
+ /**
+ *
+ * @param int $id
+ * @param string $username
+ * @param string[] $aliases
+ * @param string[] $groups
+ * @param bool $verified
+ * @param int $registered
+ * @param object $avatar
+ */
+ public function __construct(int $id, string $username, array $aliases, array $groups, bool $verified, int $registered, object $avatar)
+ {
$this->id = $id;
$this->username = $username;
$this->aliases = $aliases;
$this->groups = $groups;
$this->verified = $verified;
$this->registered = $registered;
- $this->attributes = $attributes;
$this->avatar = $avatar;
}
+ /**
+ * Returns the user's id. This is immutable and should be used to refer to the account
+ * inside applications
+ *
+ * @return int
+ */
public function getId() {
return $this->id;
}
- public function getUsername() {
+ /**
+ * The username selected by the account holder. Please note that this is mutable and the
+ * user can change it.
+ *
+ * @return string
+ */
+ public function getUsername() : string
+ {
return $this->username;
}
- public function getAvatar($size) {
+ /**
+ * Returns the avatar for the user in the selected size.
+ *
+ * @return string
+ */
+ public function getAvatar(int $size) : string
+ {
return $this->avatar->{$size};
}
- public function getGroups() {
+ /**
+ * The array of groups this user is a part of.
+ *
+ * @return string[]
+ */
+ public function getGroups() : array
+ {
return $this->groups;
}
- public function getAttribute($name) {
- if (!isset($this->attributes->{$name})) { throw new Exception("Attribute {$name} is not set"); }
- if (!is_object($this->attributes->{$name})) { return $this->attributes->{$name}->value; }
-
- $data = $this->attributes->{$name}->value;
-
- if ($data === null) {
- throw new Exception("Attribute {$name} is not set");
- }
-
- switch($data->type) {
- case 'file': return new File($data->preview, $data->download);
- default: throw new Exception('Invalid data type');
- }
- }
-
}

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 13, 10:35 AM (4 w, 6 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6095
Default Alt Text
D653.diff (10 KB)

Event Timeline