首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图形酷Github登录

图形酷Github登录
EN

Stack Overflow用户
提问于 2017-11-16 03:37:33
回答 2查看 215关注 0票数 0

我正在尝试用GitHub实现GraphCool登录。迄今为止:

步骤

  1. 我跑了:graphcool add-template auth/github
  2. 我取消了graphcool.ymltyps.graphql文件中的链接
  3. 我安装了一个GitHub OAuth应用程序
  4. 我将我的客户名称和秘密添加到本地环境变量中。
  5. 我运行了graphcool deploy

结果

在函数下面,它说我有loggedInUsergithubAuthentication。我似乎还在createUser中添加了一个createUser

问题

从这里我被困住了。我不知道该怎么办。我不知道在哪里可以获得github代码。我以前直接通过他们的API和Firebase实现了OAuth。我有以下问题:

  1. 在Github中,我应该设置什么授权回调URL?这难道不需要指出图形酷吗?
  2. 如何启动OAuth弹出窗口,以便我可以批准我的应用程序?
  3. 如何获得像displayNamephotoUrl这样的Github用户数据。在运行createUser时,我可以将该数据添加到新用户中吗?

过去,我已经将用户名密码模板修改为createUsers,并添加了其他字段。我知道我必须修改模板中的类型和.ts文件。似乎我可以在githubAuthentication.ts文件中的第29行中获得特定的用户详细信息:

代码语言:javascript
复制
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
const { githubCode } = event.data
const githubToken: string = await getGithubToken(githubCode)
const githubUser = await getGithubUser(githubToken)
const user: User = await getGraphcoolUser(api, githubUser.id)
  .then(r => r.User)
let userId: string | null = null
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-16 09:34:38

我不知道在哪里可以获得github代码。

简短的回答:无论以哪种方式,通常都会获得一个Github代码。

长答案:

您可以按照本指南来查看如何针对Github应用程序:https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-authorization-options-for-oauth-apps/进行授权。

或者,按照模板README.md中的说明操作

获取测试代码 首先,在您刚刚创建的Github上更新OAuth应用程序的配置:

  • 将主页URL设置为http://localhost:8000/
  • 将应用程序回调URL设置为http://localhost:8000/login.html
  • CLIENT_ID在login.html中替换为OAuth应用程序的客户端id
  • 服务器login.html,例如使用python -m SimpleHTTPServer
  • 在浏览器中打开https://localhost:8000/login.html,打开DevTools并使用您的Github帐户进行身份验证。
  • 复制DevTools控制台中打印的代码

这是index.html

代码语言:javascript
复制
<html>

<body>
  <script>
    // Github client id
    const client_id = '__CLIENT_ID__'
    // Will extract code from current url
    const githubCode = window.location.search.substring(1).split('&')[0].split('code=')[1]
    if (githubCode) {
      // call Graphcool authenticateGithubUser mutation
      console.log(githubCode)
    }
    function getgithubCode() {
      window.location = `https://github.com/login/oauth/authorize?client_id=${client_id}&scope=user`
    }
  </script>
  <button onclick="getgithubCode();">Authenticate with Github</button>
</body>

</html>
票数 0
EN

Stack Overflow用户

发布于 2018-01-18 12:57:59

github的医生很困惑。如果使用http-server启动服务器,则端口必须是localhost:8080,因此可以更改端口8000->8080。

此服务器用于获取githubCode。在代码中,如果应用程序的客户端ID是有效的,您可以在控制台中找到githubCode。我可以得到githubCode,但在那之后,突变就有错误了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47321158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档