// Load user's profile.
        public async Task <IActionResult> Index(string email)
        {
            if (User.Identity.IsAuthenticated)
            {
                // Get users's email.
                email ??= User.FindFirst("preferred_username")?.Value;
                ViewData["Email"] = email;

                // Initialize the GraphServiceClient.
                var graphClient = _graphServiceClientFactory.GetAuthenticatedGraphClient((ClaimsIdentity)User.Identity);

                ViewData["Response"] = await GraphService.GetUserJson(graphClient, email, HttpContext);

                ViewData["Picture"] = await GraphService.GetPictureBase64(graphClient, email, HttpContext);
            }

            return(View());
        }
Beispiel #2
0
        public IEnumerable <Doctor> Get()
        {
            var bearer_token = Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", "");
            var doctoresList = new List <Doctor>();

            try
            {
                var handler      = new JwtSecurityTokenHandler();
                var token        = handler.ReadJwtToken(bearer_token);
                var graphClient  = _graphServiceClientFactory.GetAuthenticatedGraphClient();
                var tenantIssuer = _azureOptions.TenantIssuer;

                if (token.Issuer.Contains(tenantIssuer))
                {
                    var doctores = GraphService.GetUsersList(graphClient);

                    foreach (var x in doctores.Result)
                    {
                        var doc = new Doctor
                        {
                            Telefonos      = x.BusinessPhones,
                            NombreCompleto = x.DisplayName,
                            Nombre         = x.GivenName,
                            Apellido       = x.Surname,
                            Email          = x.Mail,
                            DoctorId       = x.Id,
                            Titulo         = x.JobTitle,
                            Celular        = x.MobilePhone
                        };

                        doctoresList.Add(doc);
                    }

                    return(doctoresList);
                }
            }catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }