/// <summary> /// Gets current user from httpcontext /// </summary> /// <returns>HealthVaultIdentity</returns> public HealthVaultIdentity TryGetIdentity() { IPrincipal principal = HttpContext.Current.User; HealthVaultIdentity identity = principal?.Identity as HealthVaultIdentity; return(identity); }
/// <summary> /// Get PersonInfo for the authenticated connection. /// In case the request is not authenticated, then throws <see cref="UserNotFoundException"/> /// </summary> /// <returns>PersonInfo</returns> /// <exception cref="UserNotFoundException">When the request is not authenticated, the method will throw exception</exception> public override async Task <PersonInfo> GetPersonInfoAsync() { if (_personInfo != null) { return(_personInfo); } using (await _personInfoLock.LockAsync()) { if (_personInfo == null) { IPrincipal principal = HttpContext.Current.User; HealthVaultIdentity user = principal?.Identity as HealthVaultIdentity; if (user == null) { throw new UserNotFoundException("Request should be authorized to retrieve PersonInfo, use RequireSignIn attribute"); } WebConnectionInfo webConnectionInfo = user.WebConnectionInfo; var personInfoFromCookie = webConnectionInfo.PersonInfo; XDocument applicationSettingsDocument = null; IDictionary <Guid, HealthRecordInfo> authorizedRecords = null; // In case application settings/records are minimized due to size constraints in storing the webconnectionInfo object // as a cookie, we will restore the application settings and authorized documents from the server. if (webConnectionInfo.MinimizedPersonInfoApplicationSettings || webConnectionInfo.MinimizedPersonInfoRecords) { IPersonClient personClient = CreatePersonClient(); var personInfoFromServer = await personClient.GetPersonInfoAsync(); applicationSettingsDocument = personInfoFromServer.ApplicationSettingsDocument; authorizedRecords = personInfoFromServer.AuthorizedRecords; } _personInfo = personInfoFromCookie; if (applicationSettingsDocument != null) { _personInfo.ApplicationSettingsDocument = applicationSettingsDocument; } if (authorizedRecords != null) { _personInfo.AuthorizedRecords = authorizedRecords; } } return(_personInfo); } }