示例#1
0
        public async Task <ActionResult> AuthorizeResult(SocialNetworkType authorizeType)
        {
            var authenticateResult = await Request.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");

            if (authenticateResult != null)
            {
                IEnumerable <Claim> claims = authenticateResult.Identity.Claims;
                var currentClaim           = claims.FirstOrDefault(x => x.Type == authorizeType.ToString());
                if (currentClaim != null)
                {
                    var client = SocialNetworkClientFactory.GetClient(authorizeType, currentClaim.Value);

                    UserInfo userInfo = await client.GetUserInfo();

                    UserDisplayModel displayModel = new UserDisplayModel
                    {
                        SocialNetworkName = userInfo.SocialNetworkName,
                        Name        = userInfo.UserName,
                        Email       = userInfo.Email,
                        AccessToken = currentClaim.Value
                    };

                    return(View(displayModel));
                }
            }

            return(View("Index"));
        }
示例#2
0
        private static ISocialNetworkClient FindClient(SocialNetworkType clientType, string token)
        {
            ISocialNetworkClient client;

            var types = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == NamespaceClients).ToList();
            var type  = types.FirstOrDefault(x => x.Name == $"{clientType.ToString()}{ClientTypePostfix}");

            if (type != null)
            {
                client = (ISocialNetworkClient)Activator.CreateInstance(type, token);
            }
            else
            {
                throw new SocialNetworkException("Specific client was not found in namespace SocialNetworkClient.Clients");
            }

            return(client);
        }