-
Notifications
You must be signed in to change notification settings - Fork 390
Store state instead of session id in cookie #438
Conversation
67333a8
to
962a773
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.
Looking good, had a few comments!
src/auth/oauth/oauth.ts
Outdated
} | ||
|
||
cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, currentSession.id, { | ||
cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, session.id, { |
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 can't tell from the diff, but is this only run when not embedded? We shouldn't even need to set the session in the cookie if it's embedded, right?
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's run regardless of embedded/not-embedded ... which is the same as it does today.
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.
Technically, we could just NOT run this if Context.IS_EMBEDDED_APP
, right? Right now we're just creating a cookie that expires immediately, so it doesn't really add value.
Rather than create a temporary session in order to store a session id in a cookie for the initial OAuth transaction, we can store the state that can be compared against the state provided by Shopify in the callback, and then create the session at that point instead. Fixes Shopify/first-party-library-planning#388
0bc2390
to
991b937
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.
LGTM! 🎩ed it and it worked on all combinations of online / offline tokens + embedded / non-embedded.
src/auth/oauth/oauth.ts
Outdated
} | ||
|
||
cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, currentSession.id, { | ||
cookies.set(ShopifyOAuth.SESSION_COOKIE_NAME, session.id, { |
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.
Technically, we could just NOT run this if Context.IS_EMBEDDED_APP
, right? Right now we're just creating a cookie that expires immediately, so it doesn't really add value.
WHY are these changes introduced?
Currently, when an app calls
beginAuth
we create a temporary session and store the session id in the cookie that will be passed throughout the OAuth process. InvalidateAuthCallback
, we use the session id from the cookie to retrieve thestate
value, which we then compare to thestate
value we received from Shopify as part of the validation.Fixes https://github.com/Shopify/first-party-library-planning/issues/388
WHAT is this pull request doing?
Rather than create a temporary session in order to store a session id in a cookie for the OAuth transaction, we can store the state in the cookie instead, that can be compared against the state provided by Shopify in the callback, and then create the session at that point.
Type of change
Checklist