当前位置: 首页>>代码示例>>C#>>正文


C# IPrincipal.GetAppServiceIdentityAsync方法代码示例

本文整理汇总了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;
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:17,代码来源:ManageUserController.cs

示例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;
        }
开发者ID:MikeCodesDotNet,项目名称:Beer-Drinkin,代码行数:42,代码来源:IdentityHelper.cs

示例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;
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:18,代码来源:ManageUserController.cs


注:本文中的IPrincipal.GetAppServiceIdentityAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。