C# 具有Azure active directory令牌的提供程序的详细信息
我使用google和microsoft帐户进行azure active directory身份验证。从AAD进行身份验证后,它返回访问令牌。我们正在传入请求头。基于令牌,我想获得当前提供者的详细信息。这是否有可能通过我在标题中传递的令牌在web api代码中获得用户的详细信息 您可以从C# 具有Azure active directory令牌的提供程序的详细信息,c#,azure-mobile-services,C#,Azure Mobile Services,我使用google和microsoft帐户进行azure active directory身份验证。从AAD进行身份验证后,它返回访问令牌。我们正在传入请求头。基于令牌,我想获得当前提供者的详细信息。这是否有可能通过我在标题中传递的令牌在web api代码中获得用户的详细信息 您可以从/.auth/me端点获取各种信息。由于您将Azure移动应用程序与Xamarin表单一起使用: 为索赔建立一个模型: using System.Collections.Generic; using Newtons
/.auth/me
端点获取各种信息。由于您将Azure移动应用程序与Xamarin表单一起使用:
为索赔建立一个模型:
using System.Collections.Generic;
using Newtonsoft.Json;
namespace TaskList.Models
{
public class AppServiceIdentity
{
[JsonProperty(PropertyName = "id_token")]
public string IdToken { get; set; }
[JsonProperty(PropertyName = "provider_name")]
public string ProviderName { get; set; }
[JsonProperty(PropertyName = "user_id")]
public string UserId { get; set; }
[JsonProperty(PropertyName = "user_claims")]
public List<UserClaim> UserClaims { get; set; }
}
public class UserClaim
{
[JsonProperty(PropertyName = "typ")]
public string Type { get; set; }
[JsonProperty(PropertyName = "val")]
public string Value { get; set; }
}
}
List<AppServiceIdentity> identities = null;
public async Task<AppServiceIdentity> GetIdentityAsync()
{
if (client.CurrentUser == null || client.CurrentUser?.MobileServiceAuthenticationToken == null)
{
throw new InvalidOperationException("Not Authenticated");
}
if (identities == null)
{
identities = await client.InvokeApiAsync<List<AppServiceIdentity>>("/.auth/me");
}
if (identities.Count > 0)
return identities[0];
return null;
}
您可以从我的书中的部分获得更多信息:这是什么类型的访问令牌?通过WS-Federation,我可以从SAML令牌的声明集中获得身份提供者。声明类型称为“idp”。我在xamarin表单中使用了这段代码,var user=wait DependencyService.Get().LoginAsync(azureService.MobileService,provider);我在“MobileServiceAuthenticationToken”中获得了令牌。我知道我们可以在客户端获得用户使用.auth/me的详细信息,但我想在服务器端获得用户的详细信息,我的意思是我想在令牌的帮助下在web api中获得详细信息。服务器端记录如下:
var identity = await service.GetIdentityAsync();
if (identity != null) {
name = identity.UserClaims.FirstOrDefault(c => c.Type.Equals("name")).Value;
}