Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

anonymous auth for mobile #660

Merged
merged 13 commits into from
Jan 9, 2019
Merged

anonymous auth for mobile #660

merged 13 commits into from
Jan 9, 2019

Conversation

jessicafalk
Copy link
Contributor

@jessicafalk jessicafalk commented Dec 20, 2018

Description

  • Added anonymous functionality to the workerconnector.
  • Adjusted scenes to allow to choose between connecting locally or via cloud. we have now 2 buttons to select whether you want to connect to a local or a cloud deployment
    android

Tests

Tested on both iOS and Android. Works as expected

Documentation

docs will follow in a separate PR

Primary reviewers

If your change will take a long time to review, you can name at most two primary reviewers who are ultimately responsible for reviewing this request. @ mention them.

@improbable-prow-robot improbable-prow-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 40-149 lines, ignoring generated files. labels Dec 20, 2018
@@ -87,6 +87,7 @@ public async Task Connect(string workerType, ILogDispatcher logger)
var origin = transform.position;
ConnectionDelegate connectionDelegate;
var chosenService = GetConnectionService();
Debug.Log(chosenService);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug print


if (!string.IsNullOrEmpty(pit.Error))
{
throw new ConnectionFailedException(pit.Error, ConnectionErrorReason.InvalidConfig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is InvalidConfig actually a valid reason for failure in every case, here and below?
What if it's a different reason, for example if the service is down?

ConnectionErrorReason.InvalidConfig);
}

if (!loginTokenRequestResult.Value.Status.Equals(ConnectionStatusCode.Success))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ! .Equals, rather than !=?

@improbable-prow-robot improbable-prow-robot added size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 40-149 lines, ignoring generated files. labels Jan 7, 2019
@jessicafalk jessicafalk changed the title [WIP] anonymous auth for mobile anonymous auth for mobile Jan 7, 2019
@improbable-prow-robot improbable-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 7, 2019
Copy link
Contributor

@gkassabli gkassabli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall!

@@ -1,8 +1,8 @@
{
"name": "unity_gdk",
"project_version": "0.0.1",
"sdk_version": "13.5.0-b7795-fdd6a-WORKER-SNAPSHOT",
"sdk_version": "13.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not break our tracking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed internally: as long as we are not doing a new release it should be ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -55,6 +59,26 @@ protected override string GetHostIp()
#endif
}

protected override string GetPlayerId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to move this to MobileWorkerConnector to avoid duplication?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely some code duplication here (and in the Android one) that could be factored down to the parent class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed. on one hand, I want the user to define it, on the other hand, this is only needed in very specific cases, so the user shouldn't need to always define it... I might just move the default all the way up to the WorkerConnector until we can finally refactor this.

{
var loginTokenRequestResult = DevelopmentAuthentication.CreateDevelopmentLoginTokensAsync(
RuntimeConfigDefaults.LocatorHost,
444,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DevelopmentPlayerIdentityTokenPort?


public async void TryConnect()
public async void TryConnect(ConnectionService connectionService)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @samiwh noted on this in another PR - but should async methods have async in the name. I.e. - TryConnectAsync

@@ -55,6 +59,26 @@ protected override string GetHostIp()
#endif
}

protected override string GetPlayerId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's definitely some code duplication here (and in the Android one) that could be factored down to the parent class

protected virtual string SelectLoginToken(List<LoginTokenDetails> loginTokens)
{
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need docstrings on the new protected virtual methods in the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, knew I had forgotten something

protected virtual string GetDisplayName()
{
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this similar to other functions defined here - but I feel we should either provide a reasonable default implementation or make these fully abstract.

Returning null as a default implementation seems likely to break things later on.


if (loginTokenRequestResult.Value.Status != ConnectionStatusCode.Success)
{
throw new ConnectionFailedException($"Failed to retrieve login token, " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have a slightly longer line length than the string concatenation here.

Mild preference though

@@ -27,7 +27,7 @@ public static class LaunchArguments
}
catch (Exception e)
{
UnityEngine.Debug.LogException(e);
UnityEngine.Debug.LogWarning($"Failed to retrieve launch arguments: {e}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception -> Warning? What's the context here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will always fail, if you run this in the editor after switching to Android as current platform

therefore, it is expected behaviour to fail depending on what exactly you do and it shouldn't throw an exception imo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function even be able to be called in the editor then if it will always fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point. we could also change the part where it's called to only get called if android and not editor. or wrap this part here around an #if UNITY_EDITOR, which I would slightly prefer as it makes it safe to call for users that are not familiar with the code.

@jamiebrynes7
Copy link
Contributor

Also changelog 😛

@jamiebrynes7 jamiebrynes7 added A: mobile Area: Mobile integration T: feature Type: This is a new feature labels Jan 8, 2019
@@ -27,17 +28,20 @@ public void Awake()
if (!string.IsNullOrEmpty(hostIp))
{
ipAddressInput.text = hostIp;
TryConnect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional change? If I understand correctly this was here to automatically connect to host locally when we launch with command line arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, should have probably commented that earlier. Now that we can either connect to a local or a cloud deployment, we don‘t want to try and immediately connect to a local deployment all the time. Sure, we could remove the ip in the config, but I think this is a nicer solution as the other one would mean that you would have to look up for local ip again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me if this is explicit change.
I'd point out that this was only triggered from launch menu, where I'd expect people mostly launch for local, but I understand the reasoning.
I think this is another pointer that we need to rethink how we implement client launch configuration so that it is more transparent and processing logic is easier to separate out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure about this. As it is not required to upload the android clients to the cloud deployment, I could imagine that people want to quickly iterate and test changes and try them out in a running cloud deployment. I simply don't think we should try to immediately connect, if there are now two ways to connect, but this is all code in the playground so developers will likely use a different interface to decide how to connect.

Not sure I understand what you mean by the second point. Do you mean how we decide whether to connect to a local or a cloud deployment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this approach is more flexible.
For my second point I have a general feeling that we can improve the launch configuration and processing both in tooling and in Playground as a sample, but I don't have concrete suggestions as of the moment. Will try to think more about this and maybe come up with something more concrete.

@@ -8,6 +8,7 @@ public static class LaunchArguments
{
public static Dictionary<string, string> GetArguments()
{
#if !UNITY_EDITOR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this malfunctioning in Unity Editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as jamie and I were discussing in one of the previous threads in this PR: you can set your current platform to Android in the Editor, which will cause this code to be run. However using these java objects will only succeed in an actual android device/emulator. You end up with a nullpointer exception.

So either

  • we don‘t throw an exception
  • we don‘t run this code in the editor

We decided that not running it seems like the better option, because this code shouldn‘t fail on an actual android device

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to wrap this in Application.isEditor rather than compiling it out?

namespace Improbable.Gdk.Core
{
/// <summary>
/// Represents an error that occurs when the local state of a SpatialOS entity is not valid.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc doesn't seem to reflect the exception name

@@ -8,6 +8,7 @@ public static class LaunchArguments
{
public static Dictionary<string, string> GetArguments()
{
#if !UNITY_EDITOR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to wrap this in Application.isEditor rather than compiling it out?

Copy link
Contributor

@jamiebrynes7 jamiebrynes7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM - one small thing I'm not sure about.

throw new AuthenticationFailedException("Did not receive a player identity token.");
}

if (!string.IsNullOrEmpty(result.Value.Error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should only check for null as the underlying C API returns a null pointer if there is no error. Not sure how this gets transformed into the C# struct. cc @davedissian

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with David, we can actually just use the status code

}

/// <summary>
/// Retrieves the login tokens of all active deployments that the player
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Retrieves the login tokens for all active deployments...

@jessicafalk jessicafalk merged commit 5d4775b into master Jan 9, 2019
@jamiebrynes7 jamiebrynes7 deleted the feature/anon-auth branch January 9, 2019 18:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A: mobile Area: Mobile integration size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. T: feature Type: This is a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants