我正在尝试用GitHub实现GraphCool登录。迄今为止:
步骤
graphcool add-template auth/githubgraphcool.yml和typs.graphql文件中的链接graphcool deploy结果
在函数下面,它说我有loggedInUser和githubAuthentication。我似乎还在createUser中添加了一个createUser
问题
从这里我被困住了。我不知道该怎么办。我不知道在哪里可以获得github代码。我以前直接通过他们的API和Firebase实现了OAuth。我有以下问题:
displayName和photoUrl这样的Github用户数据。在运行createUser时,我可以将该数据添加到新用户中吗?过去,我已经将用户名密码模板修改为createUsers,并添加了其他字段。我知道我必须修改模板中的类型和.ts文件。似乎我可以在githubAuthentication.ts文件中的第29行中获得特定的用户详细信息:
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发布于 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应用程序的配置:
这是index.html
<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>发布于 2018-01-18 12:57:59
github的医生很困惑。如果使用http-server启动服务器,则端口必须是localhost:8080,因此可以更改端口8000->8080。
此服务器用于获取githubCode。在代码中,如果应用程序的客户端ID是有效的,您可以在控制台中找到githubCode。我可以得到githubCode,但在那之后,突变就有错误了。
https://stackoverflow.com/questions/47321158
复制相似问题