meteor-shopify 验证器 getPermanentAccessToken 与代码
meteor-shopify authenticator getPermanentAccessToken with code
我正在使用 froatsnook:shopify 气氛包在 Shopify 上创建一个嵌入式 public 应用程序。我目前有几个问题:
1) 在用户验证后从 "code" 查询参数获取访问令牌。正如它提到的 in the docs here,我应该使用 authenticator.getPermanentAccessToken(code)
但我不明白的是如果 "code" 参数出现在回调路由上(此时,我在客户端预授权路由上实例化的身份验证器超出范围)。
2) 由于某些原因,"oAuth" 函数回调从未被调用,即使在服务器上将其分配给 Shopify.onAuth
也是如此。
3) post_auth_uri
和redirect_uri
的区别?
// I call this during 'onBeforeAction' for iron-router
function beforeAuth (query) {
// is this necessary..?
console.assert(Meteor.isClient);
// get shop name like 'myshop' from 'myshop.shopify.com';
const shop = query.shop.substring(0, query.shop.indexOf('.'));
// use api_key stored in settings
var api_key = Meteor.settings.public.shopify.api_key;
// Prepare to authenticate
var authenticator = new Shopify.PublicAppOAuthAuthenticator({
shop: shop,
api_key: api_key,
keyset: 'default',
embedded_app_sdk: true,
redirect_uri: 'https://45a04f23.ngrok.com/testContent',
//post_auth_uri: ???
// This is doesn't seem to be getting
// called after clicking through the OAuth dialog
onAuth: function(access_token) {
ShopifyCredentials.insert({
shop: shop,
api_key: api_key,
access_token: access_token
});
}
});
// Should i use something different with iron-router?
location.href = authenticator.auth_uri;
// how do i get code in this scope???
// authenticator.getPermanentAccessToken(code);
}
您尝试设置身份验证器的方式存在一些问题,尽管这并不是您的错,因为场景 3 在文档中的工作方式不是 'out of the box' 解决方案并且需要大量自定义代码,包括您自己的处理程序(如果您真的想构建自己的处理程序,我可以提供要点,但我建议改用新的服务器端 onAuth
回调)
1. 指定 redirect_uri
覆盖包的默认 redirect_uri 处理程序,即 Meteor.absoluteUrl("/__shopify-auth")
。
因此,完全删除 redirect_uri
并将您的 testContent url 放入 post_auth_uri
中。
2. 此包中不存在 ShopifyCredentials。如果您想以这种方式使用它,请确保您确实定义了一个名为 'ShopifyCredentials' 的集合,并从服务器而不是客户端插入记录。请注意,您仍然需要在服务器 上添加一个键集 才能使API 方法起作用。如果您正在使用用户帐户并希望永久存储凭据,我建议将凭据保存到数据库并通过服务器端 onAuth 回调添加密钥集。
3. authenticator.getPermanentAccessToken(code)
没有用,除非您使用自己的处理程序。相反,您可以从 onAuth
回调中获取 access_token
。
另请记住,如果您需要从嵌入式应用程序内部重新进行身份验证,则需要使用 window.top.location.href
突破 iframe。
如果你想要一个完整的、有效的样板示例带有用户帐户,请在此处查看我的要点:
Authentication with Accounts and Persistent Keysets
如果您不使用帐户,则可以改用此要点,但请注意,您确实需要想出一些方法来检查当前客户是否有权在之前为给定商店请求密钥集投入生产:
Authentication with Persistent Keysets
我正在使用 froatsnook:shopify 气氛包在 Shopify 上创建一个嵌入式 public 应用程序。我目前有几个问题:
1) 在用户验证后从 "code" 查询参数获取访问令牌。正如它提到的 in the docs here,我应该使用 authenticator.getPermanentAccessToken(code)
但我不明白的是如果 "code" 参数出现在回调路由上(此时,我在客户端预授权路由上实例化的身份验证器超出范围)。
2) 由于某些原因,"oAuth" 函数回调从未被调用,即使在服务器上将其分配给 Shopify.onAuth
也是如此。
3) post_auth_uri
和redirect_uri
的区别?
// I call this during 'onBeforeAction' for iron-router
function beforeAuth (query) {
// is this necessary..?
console.assert(Meteor.isClient);
// get shop name like 'myshop' from 'myshop.shopify.com';
const shop = query.shop.substring(0, query.shop.indexOf('.'));
// use api_key stored in settings
var api_key = Meteor.settings.public.shopify.api_key;
// Prepare to authenticate
var authenticator = new Shopify.PublicAppOAuthAuthenticator({
shop: shop,
api_key: api_key,
keyset: 'default',
embedded_app_sdk: true,
redirect_uri: 'https://45a04f23.ngrok.com/testContent',
//post_auth_uri: ???
// This is doesn't seem to be getting
// called after clicking through the OAuth dialog
onAuth: function(access_token) {
ShopifyCredentials.insert({
shop: shop,
api_key: api_key,
access_token: access_token
});
}
});
// Should i use something different with iron-router?
location.href = authenticator.auth_uri;
// how do i get code in this scope???
// authenticator.getPermanentAccessToken(code);
}
您尝试设置身份验证器的方式存在一些问题,尽管这并不是您的错,因为场景 3 在文档中的工作方式不是 'out of the box' 解决方案并且需要大量自定义代码,包括您自己的处理程序(如果您真的想构建自己的处理程序,我可以提供要点,但我建议改用新的服务器端 onAuth
回调)
1. 指定 redirect_uri
覆盖包的默认 redirect_uri 处理程序,即 Meteor.absoluteUrl("/__shopify-auth")
。
因此,完全删除 redirect_uri
并将您的 testContent url 放入 post_auth_uri
中。
2. 此包中不存在 ShopifyCredentials。如果您想以这种方式使用它,请确保您确实定义了一个名为 'ShopifyCredentials' 的集合,并从服务器而不是客户端插入记录。请注意,您仍然需要在服务器 上添加一个键集 才能使API 方法起作用。如果您正在使用用户帐户并希望永久存储凭据,我建议将凭据保存到数据库并通过服务器端 onAuth 回调添加密钥集。
3. authenticator.getPermanentAccessToken(code)
没有用,除非您使用自己的处理程序。相反,您可以从 onAuth
回调中获取 access_token
。
另请记住,如果您需要从嵌入式应用程序内部重新进行身份验证,则需要使用 window.top.location.href
突破 iframe。
如果你想要一个完整的、有效的样板示例带有用户帐户,请在此处查看我的要点: Authentication with Accounts and Persistent Keysets
如果您不使用帐户,则可以改用此要点,但请注意,您确实需要想出一些方法来检查当前客户是否有权在之前为给定商店请求密钥集投入生产: Authentication with Persistent Keysets