Loading Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs +13 −6 Original line number Diff line number Diff line Loading @@ -106,6 +106,8 @@ namespace SampleWdpClient.UniversalWindows } }; try { // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate // with acceptUntrustedCerts set to true. This will enable untrusted connections for the // remainder of this session. Loading @@ -114,6 +116,11 @@ namespace SampleWdpClient.UniversalWindows await portal.GetRootDeviceCertificate(true); } await portal.Connect(manualCertificate: this.certificate); } catch (Exception exception) { sb.AppendLine(exception.Message); } this.MarshalUpdateCommandOutput(sb.ToString()); }); Loading WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/HttpHeadersHelper.cs +26 −4 Original line number Diff line number Diff line Loading @@ -6,12 +6,15 @@ #if !WINDOWS_UWP using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; #else using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using Windows.Web.Http; using Windows.Web.Http.Headers; #endif // !WINDOWS_UWP Loading Loading @@ -54,7 +57,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// </summary> /// <param name="client">The HTTP client on which to have the header set.</param> /// <param name="method">The HTTP method (ex: POST) that will be called on the client.</param> public void ApplyCSRFHeader( private void ApplyCSRFHeader( HttpClient client, HttpMethods method) { Loading @@ -81,7 +84,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// </summary> /// <param name="client">The HTTP client on which to have the headers set.</param> /// <param name="method">The HTTP method (ex: POST) that will be called on the client.</param> public void ApplyHttpHeaders( private void ApplyHttpHeaders( HttpClient client, HttpMethods method) { Loading @@ -94,7 +97,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// as coming from the WDPW Open Source project. /// </summary> /// <param name="client">The HTTP client on which to have the header set.</param> public void ApplyUserAgentHeader(HttpClient client) private void ApplyUserAgentHeader(HttpClient client) { string userAgentValue = UserAgentValue; Loading @@ -117,7 +120,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// Retrieves the CSRF token from the HTTP response and stores it. /// </summary> /// <param name="response">The HTTP response from which to retrieve the header.</param> public void RetrieveCsrfToken(HttpResponseMessage response) private void RetrieveCsrfToken(HttpResponseMessage response) { // If the response sets a CSRF token, store that for future requests. #if WINDOWS_UWP Loading Loading @@ -145,5 +148,24 @@ namespace Microsoft.Tools.WindowsDevicePortal } #endif } /// <summary> /// Checks a response to see if it failed due to a bad CSRF token. /// </summary> /// <param name="response">The response from the REST call.</param> /// <returns>Whether the response failed due to the bad CSRF token.</returns> private bool IsBadCsrfToken(HttpResponseMessage response) { return response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid"); } /// <summary> /// Makes a simple GET call to refresh the CSRF token. /// </summary> /// <returns>Task tracking completion of the refresh.</returns> private async Task RefreshCsrfToken() { await this.GetDeviceName(); } } } WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs +2 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Delete(uri, false); } Loading WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs +2 −2 Original line number Diff line number Diff line Loading @@ -73,9 +73,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Post(uri, requestStream, requestStreamContentType, false); } Loading WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs +2 −2 Original line number Diff line number Diff line Loading @@ -64,9 +64,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Put(uri, body, false); } Loading Loading
Samples/SampleWdpClient.UniversalWindows/MainPage.xaml.cs +13 −6 Original line number Diff line number Diff line Loading @@ -106,6 +106,8 @@ namespace SampleWdpClient.UniversalWindows } }; try { // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate // with acceptUntrustedCerts set to true. This will enable untrusted connections for the // remainder of this session. Loading @@ -114,6 +116,11 @@ namespace SampleWdpClient.UniversalWindows await portal.GetRootDeviceCertificate(true); } await portal.Connect(manualCertificate: this.certificate); } catch (Exception exception) { sb.AppendLine(exception.Message); } this.MarshalUpdateCommandOutput(sb.ToString()); }); Loading
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HttpRest/HttpHeadersHelper.cs +26 −4 Original line number Diff line number Diff line Loading @@ -6,12 +6,15 @@ #if !WINDOWS_UWP using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; using System.Threading.Tasks; #else using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using Windows.Web.Http; using Windows.Web.Http.Headers; #endif // !WINDOWS_UWP Loading Loading @@ -54,7 +57,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// </summary> /// <param name="client">The HTTP client on which to have the header set.</param> /// <param name="method">The HTTP method (ex: POST) that will be called on the client.</param> public void ApplyCSRFHeader( private void ApplyCSRFHeader( HttpClient client, HttpMethods method) { Loading @@ -81,7 +84,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// </summary> /// <param name="client">The HTTP client on which to have the headers set.</param> /// <param name="method">The HTTP method (ex: POST) that will be called on the client.</param> public void ApplyHttpHeaders( private void ApplyHttpHeaders( HttpClient client, HttpMethods method) { Loading @@ -94,7 +97,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// as coming from the WDPW Open Source project. /// </summary> /// <param name="client">The HTTP client on which to have the header set.</param> public void ApplyUserAgentHeader(HttpClient client) private void ApplyUserAgentHeader(HttpClient client) { string userAgentValue = UserAgentValue; Loading @@ -117,7 +120,7 @@ namespace Microsoft.Tools.WindowsDevicePortal /// Retrieves the CSRF token from the HTTP response and stores it. /// </summary> /// <param name="response">The HTTP response from which to retrieve the header.</param> public void RetrieveCsrfToken(HttpResponseMessage response) private void RetrieveCsrfToken(HttpResponseMessage response) { // If the response sets a CSRF token, store that for future requests. #if WINDOWS_UWP Loading Loading @@ -145,5 +148,24 @@ namespace Microsoft.Tools.WindowsDevicePortal } #endif } /// <summary> /// Checks a response to see if it failed due to a bad CSRF token. /// </summary> /// <param name="response">The response from the REST call.</param> /// <returns>Whether the response failed due to the bad CSRF token.</returns> private bool IsBadCsrfToken(HttpResponseMessage response) { return response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid"); } /// <summary> /// Makes a simple GET call to refresh the CSRF token. /// </summary> /// <returns>Task tracking completion of the refresh.</returns> private async Task RefreshCsrfToken() { await this.GetDeviceName(); } } }
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestDelete.cs +2 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Delete(uri, false); } Loading
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPost.cs +2 −2 Original line number Diff line number Diff line Loading @@ -73,9 +73,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Post(uri, requestStream, requestStreamContentType, false); } Loading
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.UniversalWindows/HttpRest/RestPut.cs +2 −2 Original line number Diff line number Diff line Loading @@ -64,9 +64,9 @@ namespace Microsoft.Tools.WindowsDevicePortal { // If this isn't a retry and it failed due to a bad CSRF // token, issue a GET to refresh the token and then retry. if (allowRetry && response.StatusCode == HttpStatusCode.Forbidden && response.ReasonPhrase.Equals("CSRF Token Invalid")) if (allowRetry && this.IsBadCsrfToken(response)) { await this.GetOperatingSystemInformation(); await this.RefreshCsrfToken(); return await this.Put(uri, body, false); } Loading