英文:
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的服务器交换以获取访问令牌。
- 创建客户端ID和客户端密钥
- 在页面上包含Google平台库
- 初始化GoogleAuth对象
- 在页面上添加登录按钮
- 用户登录
- 将授权代码发送到服务器
- 用授权代码交换访问令牌
为了更好地理解,请参考以下链接:https://developers.google.com/identity/sign-in/web/server-side-flow 和 https://cloud.google.com/go/getting-started/authenticate-users-with-iap 和 https://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.
- Create a client ID and client secret
- Include the Google platform library on your page
- Initialize the GoogleAuth object
- Add the sign-in button to your page
- Sign in the user
- Send the authorization code to the server
- 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论