Google 使用 Golang 进行身份验证和授权

标签 go authentication google-authentication

我们有供内部使用的网络应用程序,并希望通过谷歌添加身份验证。 所以认证部分非常简单。我关注了this tutorial

但是授权部分对我来说并不明显。我们在我们的系统中有不同的角色,并希望为每个谷歌帐户赋予不同的角色并在那里管理它们。 我想使用范围为 https://www.googleapis.com/auth/groups 的身份验证组 所以我有两个问题,这些组是正确的选择吗,我的意思是我们可以通过检查他属于哪个组来验证用户吗?非常感谢授权部分的任何链接

最佳答案

我在 python 中找到了这个

Google Admin SDK: Get a list of groups that a user belongs to

我还没有测试过,但我认为这是可行的方式:

package main

import (
    "context"
    "fmt"

    admin "google.golang.org/api/admin/directory/v1"
    "google.golang.org/api/option"
)

func main() {
    service, err := admin.NewService(context.Background(), option.WithCredentialsFile("cred.json"))
    if err != nil {
        panic(err)
    }
    g, err := service.Groups.List().Customer("mail@example.com").Domain("example.com").Do()
    if err != nil {
        panic(err)
    }
    fmt.Println(g)
}

来源:https://github.com/googleapis/google-api-go-client/blob/main/admin/directory/v1/admin-gen.go

关于Google 使用 Golang 进行身份验证和授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71332861/

相关文章:

android - SmsRetrieverClient 崩溃上次更新

arrays - 在 Golang 中将指针传递给字符串数组

jwt - 谷歌登录 : "Certificate for key id xxxx not found" when using google-auth Python package

Go http 监听器,每秒更新一次数据

zend-framework - IMAP "Invalid Credentials"通过 GMail XOAUTH

javascript - 复制 API key 是否意味着身份被盗?

spring - 启用身份验证时如何配置spring boot admin客户端?

android - 谷歌授权

go - 尝试使用 GORM 连接预加载时出现 panic

Golang - 从字符串中删除所有 Unicode 换行符