How can I add Google server side sign in authentication to my Golang web application?

huangapple go评论90阅读模式
英文:

How can I add Google server side sign in authentication to my Golang web application?

问题

我的问题可能缺乏具体细节,但我无法理解整个过程应该如何工作。我应该如何实施它?有哪些方法?欢迎任何指导。

我已经按照官方文档和指南进行了操作,但即使我成功实现了一些功能,我也不确定我是否做对了,因为最终结果是否符合我的需求?

我认为我需要服务器端来将会话和凭据存储到数据库中。

这是我在学校的一个附带任务,我只能使用Golang的标准包。

英文:

My question may lack specifics but I just cant understand how the whole process should work.. How I should implement it? What are the ways? Any guidance is welcome.

I have followed official documentation, their guides but even if I get something to work I dont really know if I am doing the right thing as is the end result what I need?

I think I need server side in order to store the sessions and credentials to the database.

It is a side task in my school, I am also limited to using only Golangs standard packages.

答案1

得分: 2

我不确定你具体在寻找什么,但我会提到一些可能对你有帮助的事情。

Google服务器端应用的登录:

实现一次性代码流程:
Google登录按钮提供了访问令牌和授权代码。该代码是一次性代码,您的服务器可以将其与Google的服务器交换以获取访问令牌。

  1. 创建客户端ID和客户端密钥
  2. 在页面上包含Google平台库
  3. 初始化GoogleAuth对象
  4. 在页面上添加登录按钮
  5. 用户登录
  6. 将授权代码发送到服务器
  7. 用授权代码交换访问令牌

为了更好地理解,请参考以下链接:https://developers.google.com/identity/sign-in/web/server-side-flow 和 https://cloud.google.com/go/getting-started/authenticate-users-with-iaphttps://skarlso.github.io/2016/06/12/google-signin-with-go/

在Golang中,我们有这个库:https://pkg.go.dev/golang.org/x/oauth2/google

你可以尝试使用以下示例:https://dev.to/douglasmakey/oauth2-example-with-go-3n8a

英文:

Not sure, What exactly you are looking but few things i am mentioning which might help you.

Google Sign-In for server-side apps :

Implementing the one-time-code flow :
The Google Sign-In button provides both an access token and an authorization code. The code is a one-time code that your server can exchange with Google's servers for an access token.

  1. Create a client ID and client secret
  2. Include the Google platform library on your page
  3. Initialize the GoogleAuth object
  4. Add the sign-in button to your page
  5. Sign in the user
  6. Send the authorization code to the server
  7. Exchange the authorization code for an access token

For better understanding refer here : https://developers.google.com/identity/sign-in/web/server-side-flow
and https://cloud.google.com/go/getting-started/authenticate-users-with-iap and https://skarlso.github.io/2016/06/12/google-signin-with-go/

In Golang we have this library : https://pkg.go.dev/golang.org/x/oauth2/google

This is the example you can try by your own : https://dev.to/douglasmakey/oauth2-example-with-go-3n8a

huangapple
  • 本文由 发表于 2022年1月11日 17:11:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/70664176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定