使用OneDrive SDK进行身份验证时如何获取用户信息 [英] How to get user information when authenticating with OneDrive SDK

查看:244
本文介绍了使用OneDrive SDK进行身份验证时如何获取用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建同时具有Windows桌面(非UWP)和iOS客户端的Azure应用服务.我想使用Microsoft帐户身份验证来验证用户.

I am building an Azure App Service that has both Windows Desktop (not UWP) and iOS clients. I want to use Microsoft Account Authentication to authenticate users.

由于上一个问题

As a result of a previous question here I can now authenticate users using the OneDrive SDK but have fallen at the next hurdle. The One Drive SDK does not appear to provide access to user details such as their given name and email address.

请有人指出我的示例或说明的方向,该示例或说明用于从旧学校桌面应用程序对用户进行身份验证,以允许他们使用还将提供客户端的Microsoft帐户(NOT Azure AD)访问Azure App Service.可以访问其电子邮件地址,并且不使用折旧技术.

Please can someone point me in the direction of an example or instructions for authenticating a user from an old school desktop application to allow them to access an Azure App Service using their Microsoft Account (NOT Azure AD) that will also provide the client with access to their email address and which does not use depreciated technology.

推荐答案

通过 Easy Auth 进行身份验证后,我们可以通过调用me终结点(https://{yourSiteName}/.auth/me)获取用户信息. API类似于以下代码:

After authentication via Easy Auth, we can acquire the user information from the me endpoint(https://{yourSiteName}/.auth/me) by invoking the API like code below:

var result =await client.InvokeApiAsync("/.auth/me");

要获取电子邮件,在使用OneDrive SDK进行身份验证时,我们需要wl.emails范围.然后,我们可以从me端点获取给定名称和电子邮件,例如:

And to acquire the email, we need the wl.emails scope when we authenticate with the OneDrive SDK. And after that we can get the given-name and emails from me endpoint like:

string email=(string)result[0].SelectToken("$.user_claims[?(@.typ == 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress')]")["val"]

string givenName=(string)result[0].SelectToken("$.user_claims[?(@.typ == 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname')]")["val"]

这篇关于使用OneDrive SDK进行身份验证时如何获取用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆