Skip to content
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
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

grahamsutton
Copy link

WHY are these changes introduced?

Fixes #466

Please review the changes and suggest feedback. I am still pending resolving one issue with how to dynamically provide the isOnline flag when loading the current Shopify session from the Shopify PHP library. I wanted to submit this now to incorporate feedback sooner before I remove this from being WIP.

Here's why I've decided to introduce these changes:

  • Upgrading from Laravel 8 to Laravel 10: Laravel 8 has reached end of life https://laravel.com/docs/10.x/releases#support-policy. Upgrading the framework to Laravel 10 makes sure we're using a secure and reliable version of Laravel.
  • Custom auth guard ShopifyGuard: Laravel provides many conveniences around when handling authentication through the framework, but the project in its current state bypasses Laravel's authentication (config/auth.php is completely commented out). Not being able to leverage framework benefits hurts developer productivity, causes a lot of code redundancy, and makes testing a pain (if not impossible).
  • Enable testing: Currently the project has no tests directory despite having PHPUnit configured. Developers need to be able to write unit and feature tests. Developers should not have to resort to 100% manual testing. Enabling automated testing would decrease the number of bugs escaping into deployed Shopify apps and result in a better overall brand image.

WHAT is this pull request doing?

  • Creates a custom auth guard called ShopifyGuard to return the currently authenticated session.
  • \App\Models\Session model extends \Illuminate\Foundation\Auth\User and implements missing getAuthIdentifierName and getAuthPassword methods.
  • Recreates the tests directory commonly found in fresh Laravel installations. The tests/TestCase.php class contains an overridden actingAs method that additionally injects a mock Authorization Bearer token. It also disables the Shopify middleware to allow requests in feature tests to reach the controller while still returning an authenticated \App\Models\Session instance.
  • Adds Shopify API key and secret to config/services.php.
  • Upgrades from Laravel 8 to the latest version of Laravel 10.

Checklist

Note: once this PR is merged, it becomes a new release for this template.

  • I have added/updated tests for this change
  • I have made changes to the README.md file and other related documentation, if applicable

$shopifySession = Utils::loadCurrentSession(
$request->header(),
$request->cookie(),
false
Copy link
Author

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.

@grahamsutton
Copy link
Author

I have signed the CLA!

@grahamsutton grahamsutton marked this pull request as draft September 5, 2023 21:39
'shopify' => [
'key' => env('SHOPIFY_API_KEY'),
'secret' => env('SHOPIFY_API_SECRET'),
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense for this to be in web/config/shopify.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants