-
Notifications
You must be signed in to change notification settings - Fork 96
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
[WIP] [Feature] Implement custom auth guard for Shopify sessions and enable unit and feature testing. #469
Draft
grahamsutton
wants to merge
4
commits into
Shopify:main
Choose a base branch
from
grahamsutton:project_upgrades
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4369c04
#466 - Upgrade Laravel to use version 10 (latest).
grahamsutton 72caa21
#466 - Update Session model to implement Authenticatable and enable "…
grahamsutton 9aac8cc
#466 - Enable unit and feature testing.
grahamsutton d079b1b
#466 - Fixed incorrect docblock variable name in TestCase.php.
grahamsutton 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
php-version: | ||
- "8.0" | ||
- "8.1" | ||
- "8.2" | ||
defaults: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Lib; | ||
|
||
use Illuminate\Auth\GuardHelpers; | ||
use Illuminate\Contracts\Auth\Guard; | ||
use Illuminate\Contracts\Auth\UserProvider; | ||
use Shopify\Auth\Session; | ||
use Shopify\Utils; | ||
|
||
class ShopifyGuard implements Guard | ||
{ | ||
use GuardHelpers; | ||
|
||
/** | ||
* The Shopify session instance. | ||
* | ||
* @var \Shopify\Auth\Session | ||
*/ | ||
protected Session $session; | ||
|
||
/** | ||
* The user provider fetches stored Shopify sessions. | ||
* | ||
* @var \Illuminate\Contracts\Auth\UserProvider | ||
*/ | ||
protected UserProvider $provider; | ||
|
||
/** | ||
* Create a new authentication guard for Shopify sessions. | ||
* | ||
* @param \Illuminate\Contracts\Auth\UserProvider $provider | ||
*/ | ||
public function __construct(UserProvider $provider) | ||
{ | ||
$this->provider = $provider; | ||
} | ||
|
||
/** | ||
* Get the current Shopify session. | ||
* | ||
* @return \Illuminate\Contracts\Auth\Authenticatable|null | ||
*/ | ||
public function user() | ||
{ | ||
if (! is_null($this->session)) { | ||
return $this->session; | ||
} | ||
|
||
$request = request(); | ||
|
||
if (! $request->hasHeader('Authorization')) { | ||
return; | ||
} | ||
|
||
$shopifySession = Utils::loadCurrentSession( | ||
$request->header(), | ||
$request->cookie(), | ||
false | ||
); | ||
|
||
if (is_null($shopifySession)) { | ||
return; | ||
} | ||
|
||
$this->session = $this->provider->retrieveById($shopifySession->getId()); | ||
|
||
return $this->session; | ||
} | ||
|
||
/** | ||
* Validate a user's credentials. | ||
* | ||
* Credentials are validated through Shopify sessions so we can bypass the | ||
* need to validate. | ||
* | ||
* @param array $credentials | ||
* @return bool | ||
*/ | ||
public function validate(array $credentials = []) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Via remember is disabled for Shopify sessions. | ||
* | ||
* @return bool | ||
*/ | ||
public function viaRemember() | ||
{ | ||
return false; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -30,4 +30,9 @@ | |
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), | ||
], | ||
|
||
'shopify' => [ | ||
'key' => env('SHOPIFY_API_KEY'), | ||
'secret' => env('SHOPIFY_API_SECRET'), | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes more sense for this to be in |
||
|
||
]; |
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,22 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
|
||
trait CreatesApplication | ||
{ | ||
/** | ||
* Creates the application. | ||
* | ||
* @return \Illuminate\Foundation\Application | ||
*/ | ||
public function createApplication() | ||
{ | ||
$app = require __DIR__.'/../bootstrap/app.php'; | ||
|
||
$app->make(Kernel::class)->bootstrap(); | ||
|
||
return $app; | ||
} | ||
} |
Oops, something went wrong.
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.
This is the
isOnline
flag. Any suggestions on how to dynamically populate this are welcome.