用goserver实现的github联合登录

ecdiy APPEND

配置

<Root>
    <WebExec Method="post" Url="/api/GithubOAuth">
        <Http GetUrl="https://github.com/login/oauth/access_token?client_id=****&amp;client_secret=***&amp;code=${code}"
              QueryParam="code">
            <Map>
                <Body Name="access_token"/>
            </Map>
        </Http>
        <Http GetUrl="https://api.github.com/user?${access_token}" QueryParam="access_token">
            <Json>
                <Put Name="NickName" JsonKey="login"/>
                <Put Name="OAuthId" JsonKey="id"/>
                <Put Name="AvatarUrl" JsonKey="avatar_url"/>
                <Put Name="HomeUrl" JsonKey="html_url"/>
            </Json>
        </Http>
        <ExecSp SpName="UserOAuthGithub"/>
    </WebExec>
</Root>
 <a href="https://github.com/login/oauth/authorize?client_id=****&scope=user,public_repo">
          <Icon style="font-size: 40px" type="logo-github"/>
        </a>
<template>
  <div>
。。。。。。。。
  </div>
</template>

<script>
  export default {
    layout: 'base',
    data() {
      return {}
    },
    mounted() {
      this.$Loading.start();
      var code = this.$route.query.code
      if (code && code != "") {
        this.ajax('/gk-user/api/GithubOAuth', {code: code}, (r, th) => {
          if (r.user.Code == 0) {
            th.setUser(r.user)
            this.$Loading.finish();
            th.jump("/")
          } else {
            this.$Loading.error();
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>

加入收藏 取消收藏 微博分享 49 次点击 0 回复
添加一条新回复
请尽量让自己的回复能够对别人有帮助
冀ICP备16008655号-3
返回顶端