-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactoring entry-point for Authentication Flow #14
Comments
First of all, thank you. The auth is definitely the most strange/confusing part of this package, so any improvements sound great to me. I think that your pull request sounds totally sensible. Using "close" as the default So help me understand your auth workflow. I take it from your comments that you're using an embedded app. Does the auth process start when the user navigates to your webpage directly and you say "login via shopify"? Or is your app in an iframe within the shopify admin page, then changing As for the pull request, make sure that What do you think of the following API? authenticator.openAuthTab(); // as it is now
authenticator.startAuth(); // directly navigates, as you implemented it
authenticator.startAuthInIframe(iframe); // navigates an iframe for auth Then the user wouldn't specify which |
I am only using I am using an embedded app, but that should be taken into consideration only in that I am including it as one of the potential use cases that we can optimize for. My intent is to do what makes sense for the most potential use cases with the least amount of code. That being said, I know that you have mentioned previously that you have not worked much with embedded apps so I will go over some of the pertinent details here. You cannot access an embedded app at all unless you have already gone through the auth flow to begin with. Once you have gone through the auth flow, the link to the app from the Shopify dashboard links directly to the embed. In other words, the initial authentication required to add an app to your shop never originates from within the embedded app iframe. I can think of only 2 cases where the user would need to begin the auth flow from within the iframe embedded app itself:
Scenario 1. I would consider more of an edge case where it would make sense to handle that with custom code that probably does not need to be in-package. Scenario 2. Could be handled by whichever in-package authType you wish, but would also require some type of logic that checks for an existing keyset and starts the authentication flow if none is found. When a user adds an embedded app via the App Store, they will either be directed to a landing page which you specified OR simply go DIRECTLY to the auth flow that adds the app. Since we currently MUST have a handler with this package (which in all honesty is probably not ideal), if we are not using accounts, we will always need to send them to a page that, at the very least, sets up the authenticator and immediately redirects to the Hopefully I have made all of that clear, but if you have any questions regarding that part of the flow, please let me know. Now, moving back to working with an Unfortunately I'm short on time so I have to run for the moment, but if you have any questions or thoughts thus far, please let me know and I will follow-up shortly. |
Alright, so let's look at some common usage scenarios where different authTypes would be used. This should also highlight why passing a string like Embedded Apps
Traditional Apps
Default
If I have an embedded app, chances are all the functionality is held within the embedded app itself, and it doesn't make sense to use anything other than direct
We could also check for for If we do move to an I should also note that I don't see enough of a use case for an iframe |
Another possibility would be to move the method call that passes the authConfig to a handler into the proposed Sorry I know this is all very long winded and might be hard to visualize. I keep finding myself wanting to explain things in JSON format to organize the thought process, but that would just be ridiculous! :) |
OK I'm starting to wrap my head around this. I like the following, but it's backwards incompatible. See below.
Next, using I just glanced through the code. The if (authenticatorConfig.post_auth_uri === "close") {
res.writeHead(200, { });
res.end("<html><head><script>window.close()</script></head><body></body></html>");
} else if (authenticatorConfig.embedded_app_sdk) {
res.writeHead(200, { });
res.end("<script type='text/javascript'>window.top.location.href = '" + authenticatorConfig.post_auth_uri + "';</script>");
} else {
res.writeHead(302, {
"Location": authenticatorConfig.post_auth_uri
});
res.end();
} I'm not sure why I did it like that. In the EmbeddedAppSDKTest I set
While
I agree that it doesn't seem that important to be in-package. But this made me realize that doing the handler installation in So an alternate proposal: leave the Thanks for the ideas and input! |
As for default |
OK I see that I added that code for a reason. From Shopify's docs:
This means that where the OAuth process would normally begin with: redirect_to "/auth/shopify?shop=myshopname" It should now return a page containing: <script type='text/javascript'>
window.top.location.href = '/auth/shopify?shop=myshopname';
</script> And then there's a reminder that says:
So I'm guessing that we could come up with a good default |
To construct I think it would be best to still allow an override via a specified |
I would also like to see a way to specify a default handler config for requests that originate from the App Store so that we don't have to rely on a gateway page to define the authenticator and set a handler. I'll have to look into how to accomplish that. |
I 100% agree with this one. My idea is to:
The issue is we need to identify the user client-side after the redirect. My best idea on this one would be to pass on the query parameters that shopify gives to I'll think about this more. |
Actually a gateway page isn't a huge deal if we can set the default handler using webapphandler instead of initiating it the normal way, that would solve the problem with the UUID not being set for the state parameter. That should be doable without actually having to load all the Meteor clientside JS, right? I just hate having to load up the entire Meteor client bundle for something a simple as a redirect which is the only thing I have against the gateway page. I think that should work, but I'll let you figure that one out, I have no experience with webbapphandler. I've basically already done this with a serverside route in iron:router and it would be fast and easy, but it's not good solution for most users and I'd like the package to continue to be router agnostic. I will begin working on the pull request for the other things once I am finished with the project I am finishing up and draw out a spec for the changes. |
I want to get your thoughts on this before spending the time to make the modifications for a pull request.
Currently, the only in-package way to begin the authorization flow without any "bespoke" code is using openAuthTab, and the post_auth_uri logic that is used is locked up in the Authenticator.
I started on a pull request to add the following code to Authenticators.js which I am using currently.
However, the "gotcha" of this breaking if you don't specify a post_auth_uri does not sit will with me for public usage, and I quickly found that it is not possible to overwrite this.config.post_auth_uri from here since the authConfig has already been passed in to the handler via a method call.
What I would like to propose is a single function to handle entry to authentication flow that relies on an authType passed to the Authenticator options with an appropriate fallback/default for the post_auth_uri for each authType inside Shopify.PublicAppOAuthAuthenticator.
The current functionality contained within openAuthTab would be handled with authType: 'popup', direct navigation would be authType: 'redirect', and the auth flow could be started with authenticator.startAuth();
Then in Shopify.PublicAppOAuthAuthenticator something like this:
If you are open to this, I will move ahead and make a pull request, and follow up with another for a couple other things I would like to see in the interest of optimizing for embedded app usage, such as an option to pass something like "embed" to post_auth_uri so that the path to the embedded app can be formed inside of PublicAppOAuthAuthenticator instead of inline since the shop and api key are already available there.
The text was updated successfully, but these errors were encountered: