diff --git a/Assets/MobileServices/client/MobileServiceClient.cs b/Assets/MobileServices/client/MobileServiceClient.cs index 0b1de10..5681e71 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 || UNITY_ANDROID +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Net.Security; +#endif namespace Unity3dAzure.MobileServices { @@ -22,6 +27,12 @@ public MobileServiceClient(string appUrl, string appKey) : base(appUrl) { AppUrl = appUrl; AppKey = appKey; + + // required for running in Windows and Android + #if !NETFX_CORE || UNITY_ANDROID + Debug.Log("ServerCertificateValidation"); + ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback; + #endif } public override string ToString() @@ -41,7 +52,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 +78,20 @@ public void Login(MobileServiceAuthenticationProvider provider) this.ExecuteAsync(request, callback); } + #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 + 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 1cca4e0..378a8c2 100644 Binary files a/Assets/Scenes/HighscoresDemo.unity and b/Assets/Scenes/HighscoresDemo.unity differ 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); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 3121c44..0e1c4a0 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ