-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Created Middleware to Verify Scopes and reauthenticate if required #187
Conversation
Added middleware to verify scopes. This middleware will redirect the user to authenticate route if an access_scope mentioned in config file is missing.
@usmanpakistan thanks for submitting the PR. It looks good but codecov is complaining because no unit tests have been set up for the new file. Can you write a couple test for the middleware please. |
Hi @Kyon147 <?php
namespace Osiset\ShopifyApp\Test\Http\Middleware;
use Illuminate\Auth\AuthManager;
use Osiset\ShopifyApp\Test\TestCase;
use Osiset\ShopifyApp\Util;
class VerifyScopesTest extends TestCase{
/**
* @var AuthManager
*/
protected $auth;
public function setUp(): void
{
parent::setUp();
$this->auth = $this->app->make(AuthManager::class);
}
public function testMissingScopes(): void
{
$shop = factory($this->model)->create();
$this->auth->login($shop);
// Get current Scopes
$scopes = $this->app['config']->get('shopify-app.access_scopes');
$scopes = explode(',', $scopes);
unset($scopes[0]);
$newScopes = implode(',',$scopes);
$this->app['config']->set('shopify-app.access_scopes',$newScopes);
// Run the middleware
$result = $this->runMiddleware(BillableMiddleware::class);
$this->assertStatus(302);
}
} |
No worries @usmanpakistan if you push up the test I'll take a look and edit it 👍 |
@Kyon147 Test Case added |
Any update on the PR? |
It's on my list to look at next - will see if I can squeeze this in at the weekend |
This PR adds code to resolve issues reported in #186 #185