amazon-archives / aws-sdk-unity

ARCHIVED: The aws sdk for unity is now distributed as a part of aws sdk for dotnet:
https://github.com/aws/aws-sdk-net
Other
105 stars 43 forks source link

Null ref on bad FB auth #70

Closed hgray closed 9 years ago

hgray commented 9 years ago

This one is even more obscure but caused me some confusion for a bit. If a bad access token from Facebook is passed in to Identity, we get this exception. At this point, doing a credentials.Clear() will not clear the issue and any subsequent requests to login, even as unauth will trigger the same error.

Credential exception:System.NullReferenceException: Object reference not set to an instance of an object at Amazon.CognitoIdentity.CognitoAWSCredentials.GetPoolCredentials () [0x000d0] in /Users/hgray/Documents/GSN/Mobile/GIT/aws-sdk-unity-samples/Cognito Sync Demo Project/Assets/AWSSDK/src/Services/CognitoIdentity/Custom/CognitoAWSCredentials.cs:616 at Amazon.CognitoIdentity.CognitoAWSCredentials.GenerateNewCredentials () [0x0003c] in /Users/hgray/Documents/GSN/Mobile/GIT/aws-sdk-unity-samples/Cognito Sync Demo Project/Assets/AWSSDK/src/Services/CognitoIdentity/Custom/CognitoAWSCredentials.cs:568 at Amazon.Runtime.RefreshingAWSCredentials.GetCredentials () [0x00018] in /Users/hgray/Documents/GSN/Mobile/GIT/aws-sdk-unity-samples/Cognito Sync Demo Project/Assets/AWSSDK/src/Core/Amazon.Runtime/AWSCredentials.cs:693 at Amazon.CognitoIdentity.CognitoAWSCredentials.m3F () [0x00000] in /Users/hgray/Documents/GSN/Mobile/GIT/aws-sdk-unity-samples/Cognito Sync Demo Project/Assets/AWSSDK/src/Services/CognitoIdentity/Custom/_unity/CognitoAWSCredentials.unity.cs:173 at Amazon.CognitoIdentity.CognitoIdentityAsyncExecutor+cAnonStorey2C`1[Amazon.Runtime.ImmutableCredentials].<>m40 (System.Object state) [0x00023] in /Users/hgray/Documents/GSN/Mobile/GIT/aws-sdk-unity-samples/Cognito Sync Demo Project/Assets/AWSSDK/src/Services/CognitoIdentity/Custom/_unity/CognitoIdentityAsyncExecutor.cs:42 UnityEngine.Debug:LogError(Object) SaveManager:HandleCreds(AmazonCognitoIdentityResult`1) (at Assets/DemoScene/SyncCharacterSelection/SaveManager.cs:185) Amazon.CognitoIdentity.cAnonStorey2D`1:<>m__41() (at Assets/AWSSDK/src/Services/CognitoIdentity/Custom/_unity/CognitoIdentityAsyncExecutor.cs:55) Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests() (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/_unity/UnityMainThreadDispatcher.cs:88)

albertvaka commented 9 years ago

You can make sure that credentials.GetIdentityIdAsync succeeds before passing the credentials objects to other clients. Also, note that calling credentials.Clear will only clear the current identity, but not the login providers (so the next time it will try to get a new identity with the same bad Facebook token and it will fail again). Instead of Clear, you can call RemoveLogin to remove the bad token.

hgray commented 9 years ago

Thanks, I realized that's what was happening with the providers.

That error above was to a callback I set on the get credentials, and it's not happening every time, so it's a little tough to say exactly what's causing it.

I've been running into some weird situations where I end up with an "unknown" in the SQL as the identity id. I'm trying to track down how I get into that situation. It may be related to the above situation.

albertvaka commented 9 years ago

Having "unknown" as your identity can happen if you start saving data before you get an actual identity. It shouldn't be a problem, because as soon as you get one your data will be moved into it.

hgray commented 9 years ago

Cool, thanks

hgray commented 9 years ago

Interestingly, one thing which has seemingly changed with the 2.0 release, and part of what's been throwing me off is that you no longer support offline identity creation. Is there a reason that we can't create an identity when credentials is created if none is in the player prefs? I'd think it'd be better to have something to use, rather than "unknown", especially given that a mobile device is not guaranteed to have connectivity.

hgray commented 9 years ago

Also, I'm seeing this error when testing the "Identity Only" sample project with no internet connection. The Character selection project is set up differently and fails without a connection because of the Facebook init. It doesn't contain the GetIdentityIdAsync() call so doesn't fail in the same way.

ArgumentNullException: Argument cannot be null. Parameter name: key System.Collections.Generic.Dictionary`2[System.Type,Amazon.Runtime.IExceptionHandler].TryGetValue (System.Type key, IExceptionHandler& value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588) Amazon.Runtime.Internal.ErrorHandler.ProcessException (IExecutionContext executionContext, System.Exception exception) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/ErrorHandler/ErrorHandler.cs:195) Amazon.Runtime.Internal.ErrorHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/ErrorHandler/ErrorHandler.cs:72) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.CallbackHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/CallbackHandler.cs:48) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.Signer.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/Signer.cs:41) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/CredentialsRetriever.cs:75) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.CallbackHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/CallbackHandler.cs:48) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.EndpointResolver.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/EndpointResolver.cs:37) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.Marshaller.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs:40) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.CallbackHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/CallbackHandler.cs:48) Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/PipelineHandler.cs:60) Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync (IExecutionContext executionContext) (at Assets/AWSSDK/src/Core/Amazon.Runtime/Pipeline/Handlers/ErrorCallbackHandler.cs:42) UnityEngine.Debug:LogException(Exception) IdentityManager:InitUnauth() (at Assets/DemoScene/IdentityOnlyDemo/IdentityManager.cs:158) IdentityManager:OnGUI() (at Assets/DemoScene/IdentityOnlyDemo/IdentityManager.cs:116)

albertvaka commented 9 years ago

What do you mean by offline identity creation? Our SDK has never been able to generate identities without an internet connection :/

While you are playing offline, though, there is no need for a unique identity, so it shouldn't be an issue, and the first time you get online you will automatically get one before trying to reach any AWS service and keep it potentially forever. What's the reason you say this is an issue for you?

hgray commented 9 years ago

It's entirely possible I never noticed that it required a connection before. I thought it was just building the guid at startup and then confirming it with the system before completing a sync. I had never gotten the unknown identities until this recent pass.

karthiksaligrama commented 9 years ago

Assuming this is fixed.Please reopen if otherwise