你能通过Azure go sdk接收用户信息吗?

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

Can you receive user info via Azure go sdk?

问题

我需要使用Azure服务,所以我使用github.com/Azure/azure-sdk-for-go,但我也想获取用户的电子邮件。我是否需要使用graph SDK (github.com/microsoftgraph/msgraph-sdk-go) 来实现这个功能?

我的应用程序允许多租户AD用户和个人账户进行身份验证。

英文:

I need to work with Azure services, so I use github.com/Azure/azure-sdk-for-go but also want to get a user email. Do I have to use the graph SDK (github.com/microsoftgraph/msgraph-sdk-go) for this?

My app allows authentication of both multi-tenant AD users and personal accounts.

答案1

得分: 1

是的,您需要使用msgraph-sdk-go SDK与Graph API进行交互。您可以在此处找到有关使用该SDK的更多信息:https://learn.microsoft.com/en-gb/graph/sdks/sdks-overview。

英文:

> Do I have to use the graph SDK
> (github.com/microsoftgraph/msgraph-sdk-go) for this?

Yes, you would need to use msgraph-sdk-go SDK to interact with Graph API. You can find more information about using the SDK here: https://learn.microsoft.com/en-gb/graph/sdks/sdks-overview.

答案2

得分: 1

在我的情况下,我使用了一个OAuth2令牌来对Azure和Graph SDK进行身份验证。使用相同的令牌在两个SDK中工作是不可能的,因为为Graph指定范围https://graph.microsoft.com/.default和Azure服务管理https://management.azure.com//.default会返回范围无效的错误。

因此,你不能使用Azure SDK来处理个人账户,必须使用工作账户。微软允许使用相同的电子邮件地址(但不同的密码)拥有个人和工作账户。Azure SDK确实有一个graphrbac服务,理论上可以用来获取用户电子邮件,但该服务最近被宣布为废弃。

最终,我意识到我实际上并不需要用户电子邮件,只需要订阅ID即可。

英文:

In my case I used an oauth2 token to authenticate both azure and graph SDKs. It's impossible to work with both SDKs using the same token because specifying scopes for both graph https://graph.microsoft.com/.default and azure services management https://management.azure.com//.default returns error about the scope being invalid.

So, you can't use Azure SDK for personal accounts, it must be a work account. Microsoft allows to have both personal and work account using the same email (and different passwords). Azure SDK does have graphrbac service that in theory can be used to fetch a user email but this service has been recently announced as deprecated.

I've ended up realizing I don't really need a user email, I'm fine with having a subscription ID.

huangapple
  • 本文由 发表于 2022年2月22日 23:56:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/71224351.html
匿名

发表评论

匿名网友

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

确定