-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add session checking middleware #21
Conversation
a8aa846
to
45ef62f
Compare
45ef62f
to
5fe080a
Compare
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.
Only one thing with setting up the middleware. Awesome work, as usual 👏
@@ -111,7 +111,7 @@ function(Shopify\Auth\OAuthCookie $cookie) { | |||
Route::post('/graphql', function (Request $request) { | |||
$result = Utils::graphqlProxy($request->header(), $request->cookie(), $request->getContent()); | |||
return response($result->getDecodedBody())->withHeaders($result->getHeaders()); | |||
}); | |||
})->middleware('shopify.auth:online'); |
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.
It is weird that we need to explicitly add the middlewear here even though we have added it to kernel. I don't think it should be necessary 🤔 . Maybe we have misconfigured something
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.
I actually did that on purpose - you can set up a middleware to run for a group of endpoints, but we don't want to authenticate every request, only those that are fired from the client side using authenticatedFetch
, so I added it individually to the endpoints that actually need it. Devs can definitely create a separate route group and apply the middleware to it, but I felt like keeping all the endpoints in a single file makes it easier to understand.
e53aad2
to
daf0b52
Compare
WHY are these changes introduced?
Most app requests will need to be authenticated when they interact with Shopify. In order to make it easy to ensure that a certain action is fully cleared to access the API, we should provide a middleware to run all of the checks.
WHAT is this pull request doing?
Adding a middleware that can be used as
shopify.auth[:online/:offline]
(defaulting to online), which will load the session from the current request (auth header / cookies) and check if it:If the session is not valid, the middleware will:
X-Shopify-API-Request-Failure-Reauthorize
andX-Shopify-API-Request-Failure-Reauthorize-Url
) indicating that the app should go to login.The default client in the React app was also updated to wrap around the
authenticatedFetch
call with a function that looks for those headers in the response, and breaks out of the Admin to go to/login
.Checklist