public async Task AuthorizeRestRequestAsync(HttpRequestMessage message, Guid recordId) { // Ensure we're authenticated await AuthenticateAsync().ConfigureAwait(false); if (SessionCredential.IsExpired()) { await RefreshSessionAsync(CancellationToken.None).ConfigureAwait(false); } var parts = new List <string> { $"app-token={SessionCredential.Token}" }; string connectionHeader = GetPlatformSpecificRestAuthHeaderPortion(); if (!string.IsNullOrEmpty(connectionHeader)) { parts.Add(connectionHeader); } if (recordId != Guid.Empty) { parts.Add($"record-id={recordId}"); } message.Headers.Authorization = new AuthenticationHeaderValue("MSH-V1", string.Join(",", parts)); }
private static void GetTokenByParseResponse( XPathNodeIterator navTokenIterator, SessionCredential sessionCredential) { foreach (XPathNavigator tokenNav in navTokenIterator) { sessionCredential.Token = tokenNav.Value; } }
private SessionCredential GetSessionCredential(HealthServiceResponseData responseData) { if (responseData == null) { throw new ArgumentNullException($"{nameof(responseData)}"); } SessionCredential sessionCredential = GetAuthenticationToken(responseData.InfoNavigator); // TODO: Update with returned expiry when #55406 is completed. 4h is the default HealthVault token expiry time sessionCredential.ExpirationUtc = DateTimeOffset.UtcNow.AddHours(4); return(sessionCredential); }
/// <summary> /// Extracts the authentication token from the response XML. /// </summary> /// /// /// <param name="nav"> /// The path to the token. /// </param> /// private SessionCredential GetAuthenticationToken( XPathNavigator nav) { SessionCredential sessionCredential = new SessionCredential(); XPathExpression authTokenPath = GetAuthTokenXPath(nav); XPathNodeIterator navTokenIterator = nav.Select(authTokenPath); GetTokenByParseResponse(navTokenIterator, sessionCredential); XPathNavigator sharedSecret = nav.SelectSingleNode("shared-secret"); sessionCredential.SharedSecret = sharedSecret.Value; return(sessionCredential); }