From c0826f7c2efa4ab7ad2a3dd967f28269a3e0df1c Mon Sep 17 00:00:00 2001 From: David Douglas Date: Mon, 24 Aug 2015 10:24:16 +0100 Subject: [PATCH 1/2] windows and android update --- .../client/MobileServiceClient.cs | 29 +++++++++++++++++- Assets/MobileServices/http/ZumoRequest.cs | 24 --------------- Assets/MobileServices/model/AccessToken.cs | 3 ++ Assets/Scenes/HighscoresDemo.unity | Bin 11384 -> 11676 bytes Assets/Scripts/HighscoresDemoUI.cs | 8 +---- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Assets/MobileServices/client/MobileServiceClient.cs b/Assets/MobileServices/client/MobileServiceClient.cs index 0b1de10..1753c80 100644 --- a/Assets/MobileServices/client/MobileServiceClient.cs +++ b/Assets/MobileServices/client/MobileServiceClient.cs @@ -3,6 +3,11 @@ using RestSharp; using System.Collections.Generic; using System; +#if !NETFX_CORE +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Net.Security; +#endif namespace Unity3dAzure.MobileServices { @@ -22,6 +27,13 @@ public MobileServiceClient(string appUrl, string appKey) : base(appUrl) { AppUrl = appUrl; AppKey = appKey; + + // required for running in Windows + #if !NETFX_CORE || UNITY_ANDROID + Debug.Log("ServerCertificateValidation"); + //ServicePointManager.ServerCertificateValidationCallback = (p1, p2, p3, p4) => true; // NB: this is a workaround for "Unable to find /System/Library/Frameworks/Security.framework/Security" issue in Android + ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback; + #endif } public override string ToString() @@ -41,7 +53,7 @@ public void Login(MobileServiceAuthenticationProvider provider, string token, Ac { string uri = "login/" + provider.ToString().ToLower(); ZumoRequest request = new ZumoRequest(this, uri, Method.POST); - Debug.Log( "Login Request Uri: " + uri ); + Debug.Log("Login Request Uri: " + uri + " access token: " + token); request.AddBodyAccessToken(token); this.ExecuteAsync(request, callback); } @@ -67,5 +79,20 @@ public void Login(MobileServiceAuthenticationProvider provider) this.ExecuteAsync(request, callback); } + #if !NETFX_CORE + private bool RemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + { + // Check the certificate to see if it was issued from Azure + if (certificate.Subject.Contains("azurewebsites.net")) + { + return true; + } + else + { + return false; + } + } + #endif + } } \ No newline at end of file diff --git a/Assets/MobileServices/http/ZumoRequest.cs b/Assets/MobileServices/http/ZumoRequest.cs index 326a7eb..83f23ad 100644 --- a/Assets/MobileServices/http/ZumoRequest.cs +++ b/Assets/MobileServices/http/ZumoRequest.cs @@ -1,11 +1,6 @@ using UnityEngine; using System.Collections; using RestSharp; -#if !NETFX_CORE -using System.Net; -using System.Security.Cryptography.X509Certificates; -using System.Net.Security; -#endif namespace Unity3dAzure.MobileServices { @@ -22,10 +17,6 @@ public ZumoRequest(MobileServiceClient client, string uri, Method httpMethod) : this.AddHeader("X-ZUMO-AUTH", client.User.authenticationToken); Debug.Log("Auth UserId:" + client.User.user.userId); } - // required for running in Windows - #if !NETFX_CORE - ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback; - #endif } public void AddBodyAccessToken(string token) @@ -34,20 +25,5 @@ public void AddBodyAccessToken(string token) this.AddBody(accessToken); } - #if !NETFX_CORE - private bool RemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) - { - // Check the certificate to see if it was issued from Azure - if ( certificate.Subject.Contains("azurewebsites.net") ) - { - return true; - } - else - { - return false; - } - } - #endif - } } diff --git a/Assets/MobileServices/model/AccessToken.cs b/Assets/MobileServices/model/AccessToken.cs index 7f43cbb..6bf97bd 100644 --- a/Assets/MobileServices/model/AccessToken.cs +++ b/Assets/MobileServices/model/AccessToken.cs @@ -11,5 +11,8 @@ public AccessToken(string accessTokenValue) { access_token = accessTokenValue; } + + /// Needed only for Serialization (Fixes error: AccessToken cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute) + public AccessToken() {} } } \ No newline at end of file diff --git a/Assets/Scenes/HighscoresDemo.unity b/Assets/Scenes/HighscoresDemo.unity index 1cca4e0e08f5cc95338f2f06dabff781b01d3cec..e2f2ab4cd16726d885526ef32fe06d121b72c9a2 100644 GIT binary patch delta 332 zcmWO1J92_R7yw|BN#QZlnMNh37*b_d5rZO6dHkth7KEVdg9VkwE~oGknVcpwsdI*u zvHzOy&%eAiIPT$v<64)`#!vH>-F*EvKkm*=j^k3sw#9R&L*kIEPDw_W@xEw>b-9mQ z>rIrc;x>(0hr7SpND0<*21=zdQtS?FO&c?t={+9T6| z%&m#&>0|0|bP58JVk@uY4RaYF9&aqaZ4FuLyk0hy(2 ArT_o{ delta 29 lcmbOe{Ud^dfkDH8fkCHYBgY+erT~V`&(zykChKYP004z(2&w=8 diff --git a/Assets/Scripts/HighscoresDemoUI.cs b/Assets/Scripts/HighscoresDemoUI.cs index 99358ad..7d879f6 100644 --- a/Assets/Scripts/HighscoresDemoUI.cs +++ b/Assets/Scripts/HighscoresDemoUI.cs @@ -37,13 +37,7 @@ public class HighscoresDemoUI : MonoBehaviour /// Use this for initialization void Start () - { - /// NB: Warning this block disables ServerCertificateValidation on Android for demo purposes only! - #if UNITY_ANDROID - Debug.Log("Warning: Android ServerCertificateValidation disabled."); - ServicePointManager.ServerCertificateValidationCallback = (p1, p2, p3, p4) => true; // NB: this is a workaround for "Unable to find /System/Library/Frameworks/Security.framework/Security" issue in Android - #endif - + { /// Create Mobile Service client _client = new MobileServiceClient(_appUrl, _appKey); Debug.Log(_client); From 2d4e340dbf2e46c01d81810036b2b41a391f2334 Mon Sep 17 00:00:00 2001 From: David Douglas Date: Mon, 24 Aug 2015 10:54:28 +0100 Subject: [PATCH 2/2] Windows and Android ServerCertificateValidation. Resolves #5 --- .../client/MobileServiceClient.cs | 9 ++++----- Assets/Scenes/HighscoresDemo.unity | Bin 11676 -> 11672 bytes ProjectSettings/ProjectSettings.asset | Bin 36781 -> 36781 bytes 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Assets/MobileServices/client/MobileServiceClient.cs b/Assets/MobileServices/client/MobileServiceClient.cs index 1753c80..5681e71 100644 --- a/Assets/MobileServices/client/MobileServiceClient.cs +++ b/Assets/MobileServices/client/MobileServiceClient.cs @@ -3,7 +3,7 @@ using RestSharp; using System.Collections.Generic; using System; -#if !NETFX_CORE +#if !NETFX_CORE || UNITY_ANDROID using System.Net; using System.Security.Cryptography.X509Certificates; using System.Net.Security; @@ -28,10 +28,9 @@ public MobileServiceClient(string appUrl, string appKey) : base(appUrl) AppUrl = appUrl; AppKey = appKey; - // required for running in Windows + // required for running in Windows and Android #if !NETFX_CORE || UNITY_ANDROID - Debug.Log("ServerCertificateValidation"); - //ServicePointManager.ServerCertificateValidationCallback = (p1, p2, p3, p4) => true; // NB: this is a workaround for "Unable to find /System/Library/Frameworks/Security.framework/Security" issue in Android + Debug.Log("ServerCertificateValidation"); ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback; #endif } @@ -79,7 +78,7 @@ public void Login(MobileServiceAuthenticationProvider provider) this.ExecuteAsync(request, callback); } - #if !NETFX_CORE + #if !NETFX_CORE || UNITY_ANDROID private bool RemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { // Check the certificate to see if it was issued from Azure diff --git a/Assets/Scenes/HighscoresDemo.unity b/Assets/Scenes/HighscoresDemo.unity index e2f2ab4cd16726d885526ef32fe06d121b72c9a2..378a8c207c7507352b2620decda5ea0424362a56 100644 GIT binary patch delta 284 zcmbOeJtJC@fkDH8fkAf$0|Ns;kevXe8BFyI^^7)3o>pfpnEX^-MZmoFy}tHg_qfGJ zJoX=vU-W6Sq{d>F`l~>d&W?`WIblXs#z~cqPLA##9)@L}7Ku)k5hm$o298-ip_ze! z9*$8?j+q5zh1pJ)p+)6RX(`5qmcGVOj!}-L#wC%Ze&L~pY31%|QO>TWPM$%LA%0O# zu0Ex1K~avGVWHmMu4N@jNkyd|Ibo$~=HA|^a!CFPcB dxyj*~79}o`#^w1z*%6gyRpn7GQ7%A_0RV2dTh#yn delta 288 zcmbOcJtta{fkDH8fkAf;0|Ns;kevXe8BFyI^$a&ko>pfpnfz2;MWA{4Z;#aK*X}DM zWwY+@m%hANQe!bo{Y{`sXGcfxoG_y* zXP?q+%MdRE-zcYmh>R#llfd){%P6N{vw%|9DCdxLS97l@C&Nr%fAdT?pMqk4m-H;7 zG@r;)i>kuXv@}o0DuW~=%hD*Pl7L_%C$qA$iX`I{r?jHP5VI(!#FD&H*O0J^6cZzN z--5~vOOMQO_moJps_+!=$P~XI53_K8x4eja|GX$i%haIkGS~c)u#zZ81E>6;2-Dz{ g)Uqh2D93Q)LQ~UNmT06!R9^MjIuk^aB7YR0U-K delta 14 WcmZ2GpK0xUrU?>^h8rcP^aB7YPX%NE