-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smart standalone patientrole migrate #4177
Merged
bradymiller
merged 15 commits into
openemr:master
from
adunsulag:smart-standalone-patientrole-migrate
Jan 28, 2021
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
222f6b1
OAUTH2 Standalone Provider Patient Selector
adunsulag 11bf0e5
Patient Endpoint, SMART Standalone launch changes.
adunsulag 10189df
Register App standalone scope selection and ux/ui.
adunsulag c90104b
migrate patientrole to main fhir api route
bradymiller 817a14e
Centralized scope checks for rest api. Perm update
adunsulag 9358259
Fix patient routes to use patient uuid.
adunsulag 0a6009a
Better error log / debug logs on oauth2 client validation
adunsulag 3a155ce
Fix fhirUser claim for patient context login.
adunsulag 43ff24a
Standalone SMART response handler
adunsulag 10b0826
Offline access support, client-public support.
adunsulag 2fba346
Fix unit tests and style problems.
adunsulag 583418b
Fix patient context missing for standalone.
adunsulag c18963d
Inferno Limited Scope Authorization
adunsulag 035edd0
Fix style errors.
adunsulag 75750ec
Fix translate, escape, and comments.
adunsulag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Standalone SMART response handler
Fixed some scope permission checks. Refactored the route parsing algorithm into its own class that can be unit tested against. The parsing logic could then be leveraged in the scope auth check which made matching against the REST FHIR resource a lot easier. Added the additional SMART capabilities we now support with patient standalone and launch standalone. Fixed the refresh token issues. We don't send patient context parameters as part of the refresh_grant oauth2 flow so we only send the parameters now in the authorization_grant flow inside our SMARTResponse object. There may be a better way to make this work, but for now this is functioning.
- Loading branch information
commit 43ff24aecbd68e84115ffecf3aee638dfc652012
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* HttpRestParsedRoute represents a parsed http rest api request. It splits apart an OpenEMR route definition and | ||
* parses the provided http request against that route definition. Validates the route definition and extracts the | ||
* resource name as well as any route parameters defined in the route definition. | ||
* @package openemr | ||
* @link http://www.open-emr.org | ||
* @author Stephen Nielson <stephen@nielson.org> | ||
* @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
namespace OpenEMR\Common\Http; | ||
|
||
|
||
use OpenEMR\Common\Logging\SystemLogger; | ||
|
||
class HttpRestParsedRoute | ||
{ | ||
|
||
/** | ||
* Whether the route definition is a valid match against the current request | ||
* @var bool | ||
*/ | ||
private $isValid; | ||
|
||
/** | ||
* The endpoint resource that the api request is for. Only populated if the route definition | ||
* matches against the current route | ||
* @var string | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* The endpoint paramters (identifiers, and anything else marked with the :colon param). | ||
* Only populated if the route definition matches against the current route | ||
* @var string | ||
*/ | ||
private $routeParams; | ||
|
||
/** | ||
* The OpenEMR route definition that this request is being matched / parsed against | ||
* @var string | ||
*/ | ||
private $routeDefinition; | ||
|
||
/** | ||
* The current HTTP request route we are attempting to match against a route definition | ||
* @var string | ||
*/ | ||
private $requestRoute; | ||
|
||
public function __construct($requestMethod, $requestRoute, $routeDefinition) | ||
{ | ||
$this->routeDefinition = $routeDefinition; | ||
$this->requestRoute = $requestRoute; | ||
$this->requestMethod = $requestMethod; | ||
|
||
$routePieces = explode(" ", $routeDefinition); | ||
$routeDefinitionMethod = $routePieces[0]; | ||
$pattern = $this->getRouteMatchExpression($routePieces[1]); | ||
$matches = array(); | ||
if ($requestMethod === $routeDefinitionMethod && preg_match($pattern, $requestRoute, $matches)) { | ||
$this->isValid = true; | ||
array_shift($matches); // drop request method | ||
$this->routeParams = $matches; | ||
$this->resource = $this->getResourceForRoute($routeDefinition); | ||
(new SystemLogger())->debug("HttpRestParsedRoute->__construct() ", ['routePath' => $routeDefinition, | ||
'requestPath' => $requestRoute | ||
,'method' => $requestMethod, 'routeParams' => $this->routeParams, 'resource' => $this->getResource()]); | ||
} | ||
else { | ||
$this->isValid = false; | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the | ||
* | ||
* @return boolean | ||
*/ | ||
public function isValid() { | ||
return $this->isValid; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getResource(): string | ||
{ | ||
return $this->resource; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRouteParams(): array | ||
{ | ||
return $this->routeParams; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRouteDefinition() | ||
{ | ||
return $this->routeDefinition; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRequestRoute() | ||
{ | ||
return $this->requestRoute; | ||
} | ||
|
||
/** | ||
* Returns the regex for a given path we use to match against a route. | ||
* @param $path | ||
* @return string | ||
*/ | ||
private function getRouteMatchExpression($path) { | ||
// Taken from https://stackoverflow.com/questions/11722711/url-routing-regex-php/11723153#11723153 | ||
return "@^" . preg_replace('/\\\:[a-zA-Z0-9\_\-]+/', '([a-zA-Z0-9\-\_\$]+)', preg_quote($path)) . "$@D"; | ||
} | ||
|
||
|
||
private function getResourceForRoute($routePath) { | ||
$parts = explode("/", $routePath); | ||
$finalArg = end($parts); | ||
if (strpos($finalArg, ':') !== false) { | ||
array_pop($parts); | ||
$finalArg = end($parts); | ||
} | ||
return $finalArg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat! the
splat
operator:https://blog.programster.org/php-splat-operator