本文整理汇总了C#中IPrincipal.GetAppServiceIdentityAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IPrincipal.GetAppServiceIdentityAsync方法的具体用法?C# IPrincipal.GetAppServiceIdentityAsync怎么用?C# IPrincipal.GetAppServiceIdentityAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPrincipal
的用法示例。
在下文中一共展示了IPrincipal.GetAppServiceIdentityAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserId
internal static async Task<string> GetUserId(HttpRequestMessage request, IPrincipal user)
{
ClaimsPrincipal principal = user as ClaimsPrincipal;
string provider = principal.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider").Value;
ProviderCredentials creds = null;
if (string.Equals(provider, "facebook", StringComparison.OrdinalIgnoreCase)) {
creds = await user.GetAppServiceIdentityAsync<FacebookCredentials>(request);
}
else if (string.Equals(provider, "aad", StringComparison.OrdinalIgnoreCase)) {
creds = await user.GetAppServiceIdentityAsync<AzureActiveDirectoryCredentials>(request);
}
return creds != null ?
string.Format("{0}:{1}", creds.Provider, creds.Claims[ClaimTypes.NameIdentifier]) :
null;
}
示例2: FindSidAsync
public static async Task<string> FindSidAsync(IPrincipal claimsPrincipal, HttpRequestMessage request)
{
var aiTelemetry = new TelemetryClient();
var principal = claimsPrincipal as ClaimsPrincipal;
if (principal == null)
{
aiTelemetry.TrackEvent("FindSidAsync: ClaimsPrincipal is null!");
return string.Empty;
}
var match = principal.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider");
string provider;
if (match != null)
provider = match.Value;
else
{
aiTelemetry.TrackEvent("FindSidAsync: Can't find identity provider");
return string.Empty;
}
ProviderCredentials creds = null;
if (string.Equals(provider, "facebook", StringComparison.OrdinalIgnoreCase))
{
creds = await claimsPrincipal.GetAppServiceIdentityAsync<FacebookCredentials>(request);
}
else if (string.Equals(provider, "microsoftaccount", StringComparison.OrdinalIgnoreCase))
{
creds = await claimsPrincipal.GetAppServiceIdentityAsync<MicrosoftAccountCredentials>(request);
}
else if (string.Equals(provider, "twitter", StringComparison.OrdinalIgnoreCase))
{
creds = await claimsPrincipal.GetAppServiceIdentityAsync<TwitterCredentials>(request);
}
if (creds == null)
{
aiTelemetry.TrackEvent("FindSidAsync: Credentials not found");
return string.Empty;
}
return creds.UserId;
}
示例3: IsAadLogin
// return true if user is logged in with AAD
internal static async Task<bool> IsAadLogin(HttpRequestMessage request, IPrincipal user)
{
ClaimsPrincipal principal = user as ClaimsPrincipal;
var claim = principal.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider");
if (claim == null) {
return false;
}
if (string.Equals(claim.Value, "aad", StringComparison.OrdinalIgnoreCase)) {
var creds = await user.GetAppServiceIdentityAsync<AzureActiveDirectoryCredentials>(request);
return creds != null;
}
return false;
}