Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Assets/MobileServices/client/MobileServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand All @@ -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);
}
Expand All @@ -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

}
}
24 changes: 0 additions & 24 deletions Assets/MobileServices/http/ZumoRequest.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand All @@ -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

}
}
3 changes: 3 additions & 0 deletions Assets/MobileServices/model/AccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
}
Binary file modified Assets/Scenes/HighscoresDemo.unity
Binary file not shown.
8 changes: 1 addition & 7 deletions Assets/Scripts/HighscoresDemoUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.