【问题标题】:What is the use of OAuth example in Polaris React App Bridge documentation?Polaris React App Bridge 文档中 OAuth 示例的用途是什么?
【发布时间】:2019-01-24 21:11:34
【问题描述】:

阅读文档here 和代码 sn-p 示例。这是否意味着持续检查用户是否登录到嵌入式应用程序或用于初始注册/登录过程?

另外,如果我已经在使用AppProvider 组件,这还需要吗?我知道AppProvider 处理初始化,根据他们的文档here

这是他们文档中的示例:

import createApp from '@shopify/app-bridge';
import {Redirect} from '@shopify/app-bridge/actions';

const apiKey = 'API key from Shopify Partner Dashboard';
const redirectUri = 'whitelisted redirect URI from Shopify Partner Dashboard';
const permissionUrl = `/oauth/authorize?client_id=${apiKey}&scope=read_products,read_content&redirect_uri=${redirectUri}`;

// If the current window is the 'parent', change the URL by setting location.href
if (window.top == window.self) {
  window.location.assign(`https://${shopOrigin}/admin/${permissionUrl}`)

// If the current window is the 'child', change the parent's URL with Shopify App Bridge's Redirect action
} else {
  const app = createApp({
    apiKey: apiKey,
    shopOrigin: shopOrigin,
  });

  Redirect.create(app).dispatch(Redirect.Action.ADMIN_PATH, permissionUrl);
}

【问题讨论】:

  • 你有没有想过这个问题?这是否意味着permissionUrl 应该是每个使用我们应用程序的商家(甚至那些已经安装它的商家)的入口点?有没有一种方法可以快速确定商家是否已经安装了您的应用程序来绕过这个,而只是创建(应用程序)?我唯一能想到的是做一个条件,我验证他们来自的初始 url 的 hmac,然后向 Shopify 管理 api 发出请求以查看他们的访问令牌是否有效;如果是这样,我将只创建(应用程序),但如果不是,那么我会将它们路由到 permissionUrl。

标签: reactjs shopify polaris


【解决方案1】:

我在实施 oauth 旅程几周后发现了该页面,并且同样对它的使用感到困惑。

但现在我知道我将在以下场景中使用他们的示例:当用户即将使用需要他们之前未授予应用程序权限的功能并且我需要将他们重定向到授权页面时。我尝试了一个简单的重定向,当然禁止加载管理页面,因为我仍在 iframe 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2016-04-05
    相关资源
    最近更新 更多