如何使用单独的API服务器处理Nuxt中的oauth?

问题描述 投票:0回答:1

目前我有两个独立的应用程序

  1. 前端(Nuxt)
  2. 后端(Golang)

在后端,我正在使用名为Goth的第三方库,我正在使用Facebook作为提供商。后端一切正常,但我对如何处理Nuxt侧的前端感到困惑

所以在后端技术上会有两个网址

 /auth/facebook

/auth/facebook/callback

一旦一切正确,我将从后端的facebook获取对象,这是用Golang编写的API

 data: {
         RawData: {
             email: "[email protected]",
             first_name: "John",
             id: "123123",
             last_name: "Grave",
             name: "John Grave",
             picture: {
                 data: {
                     height: 50,
                     is_silhouette: true,
                     url: "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=13123123&height=50&width=50&ext=1553079619&hash=AeTX5RW5K_avWLbI",
                     width: 50
                 }
             }
         },
         Provider: "facebook",
         Email: "[email protected]",
         Name: "John Grave",
         FirstName: "John",
         LastName: "Grave",
         NickName: "John Grave",
         Description: "",
         UserID: "123123",
         AvatarURL: "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=2312802522337124&height=50&width=50&ext=1553079619&hash=AeTX5RW5K_avWLbI",
         Location: "",
         AccessToken: "EAAIuR3NSCPwBAEcp2jskHuUCzdWLB97Aq99nCV5HuieVVz8xGfJ6exAZDZD",
         AccessTokenSecret: "",
         RefreshToken: "",
         ExpiresAt: "2019-04-19T15:52:59.895655+08:00"
     },
     status: 200
 }

假设后端的一切正常。

我唯一能想到的是在方法上调用它(Nuxt侧)

export default {
  methods: {
    facebookLogin() {
      window.location.href = `http://localhost:8080/auth/facebook`
    }
  }
}

这只会重定向到

http://localhost:8080/auth/facebook/callback?code=AQAaq9GYcGAnQ9wUCDAd5BFRHxMRjqGFR0J6zjGtYpD-

我应该采取哪些正确步骤与后端OAuth API进行通信?

谢谢!

go vue.js nuxt.js
1个回答
0
投票

您好@sinusGob你可以使用这个nuxt的auth插件

查看文档。 https://auth.nuxtjs.org/reference/providers/facebook

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.