Created
September 20, 2018 11:24
-
-
Save KevinMcDonnell-BC/6ad42e12cda7f78bcb42a75505439f69 to your computer and use it in GitHub Desktop.
BCServerlessDemo DataAndFunctions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<UserDigest> CurrentUserAsync(HttpRequestMessage req) | |
| { | |
| var userIssuer = ClaimsPrincipal.Current.Claims.Where(f => f.Type.Contains("name")).FirstOrDefault(); | |
| if (userIssuer != null && userIssuer.Issuer.ToUpper() == "LOCAL AUTHORITY") | |
| { | |
| if (req != null) | |
| { | |
| IEnumerable<string> ids = new List<string>(); | |
| req.Headers.TryGetValues("UserId", out ids); | |
| if (ids != null && ids.Any()) | |
| { | |
| var userId = ids.First(); | |
| var user = await _userRepository.GetItemAsync(userId); | |
| if (user != null) | |
| { | |
| return new UserDigest() | |
| { | |
| Id = user.id, | |
| DisplayName = user.displayName, | |
| OrganisationId = user.organisationId, | |
| AppRole = user.AppRole == null ? Role.Driver : Enums.Parse<Role>(user.AppRole), | |
| DriverId= user.driverId | |
| }; | |
| } | |
| } | |
| } | |
| var userDigest = new UserDigest() | |
| { | |
| Id = "0cdde2ed-04e4-47d9-95b1-23df587a03b6", | |
| DisplayName = "Test Account", | |
| OrganisationId = "admin", | |
| AppRole = Role.Admin, | |
| //OrganisationId = "1985651c-f63f-4bd0-9ebf-888f46376c66", | |
| //AppRole = Role.TrainingProviderAdmin, | |
| //DriverId= "7051831e-3ec9-4615-bb6f-a8b0bf709b7e" | |
| }; | |
| return userDigest; | |
| } | |
| else | |
| { | |
| var objectId = ClaimsPrincipal.Current.Claims.Where(f => f.Type.Contains("nameidentifier")).FirstOrDefault().Value.ToString(); | |
| //var objectId = ClaimsPrincipal.Current.Claims.First(f => f.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").Value; | |
| var user = await _userRepository.GetItemAsync(objectId); | |
| return new UserDigest() | |
| { | |
| Id = user.id, | |
| DisplayName = user.displayName, | |
| OrganisationId = user.organisationId, | |
| AppRole = Enums.Parse<Role>(user.AppRole), | |
| DriverId= user.driverId | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment