Azure Mobile Services authentication not working with Windows Phone 8.1 Universal app - windows-phone-8.1

I'm adding Azure Mobile Services authentication to a Universal Windows project. It's all set up and working properly on the server and in the Windows Store version of the app, however I can't get it to work with the Windows Phone 8.1 version of the app. I actually have two different apps that I've been working on with the same problem, so I created a test app based strictly on the steps outlined in this article. The sample app has one button on the UI that will attempt authenticate the user with Twitter when pressed.
The flow that I am seeing from the UI is:
Press the button
Screen goes black for a moment
Screen displays "Resuming..." with a spinner
InvalidOperationException gets caught
The exception details:
System.InvalidOperationException was caught
HResult=-2146233079
Message=Authentication was cancelled by the user.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceAuthentication.<LoginAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MobileAuthTest.MainPage.<AuthenticateAsync>d__3.MoveNext()
InnerException:
The code I am using is copied almost verbatim from the article, but I'll paste it here too:
private async void Button_Click(object sender, RoutedEventArgs e)
{
await this.AuthenticateAsync();
}
// Define a method that performs the authentication process
// using a Twitter sign-in.
private async Task AuthenticateAsync()
{
while (user == null)
{
string message;
try
{
// Change 'MobileService' to the name of your MobileServiceClient instance.
// Sign-in using Twitter authentication.
user = await App.mobileService
.LoginAsync(MobileServiceAuthenticationProvider.Twitter);
message =
string.Format("You are now signed in - {0}", user.UserId);
}
catch (InvalidOperationException)
{
message = "You must log in. Login Required";
}
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
And this override is in App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
// Windows Phone 8.1 requires you to handle the respose from the WebAuthenticationBroker.
#if WINDOWS_PHONE_APP
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
// Completes the sign-in process started by LoginAsync.
// Change 'MobileService' to the name of your MobileServiceClient instance.
mobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
#endif
base.OnActivated(args);
}
My testing is all on a real Windows Phone 8.1 device (Nokia 920 with 8.1 update).
It's also worth pointing out that the project I'm currently trying to get this to work in is also using Xamarin.Forms for Android, iOS and Windows Phone (I wanted a comparison between Xamarin.Forms for Windows Phone and Universal apps for Windows Phone). All of the apps work, EXCEPT for the two Windows Phone apps. The Xamarin.Forms Windows Phone app is a Windows Phone Silverlight 8.1 app which acts the same as described above for the Universal WP, but fails with the error, "Authentication failed with HTTP response code 0."
I've searched around and haven't found any other cases of people encountering the same issue I am. Is there something I need to do that is so simple nobody feels the need to say it in writing?

Well, it turns out that the issue I am seeing may just be my device. I sent the sample app to another dev for testing and he had no issues. I also was able to successfully log in with both the sample app and the real app on the simulator. That isn't exactly a thorough test sample, but it's enough for me to stop banging my head on this desk.

Related

Windows Phone 10 File Save Picker Not Working

I'm having trouble getting the "file save picker" contract working in Windows Phone 10 for my Universal Windows App. I've added both "File Save Picker" and "Cached File Updater" declarations to the app manifest.
It works fine for me on a full Windows 10 computer (tested Mail and Mobile Word).
When I try it on a phone running WP10, I get a native exception A heap has been corrupted (parameters: 0x77344270) with error code 0xc0000374. No part of the stacktrace leads into my app.
My TargetFileRequested listener:
private async void FileSavePickerUI_TargetFileRequested(
FileSavePickerUI sender,
TargetFileRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
var filePath = GetSelectedFilePath();
args.Request.TargetFile = await StorageFile.GetFileFromPathAsync(filePath);
CachedFileUpdater.SetUpdateInformation(
args.Request.TargetFile,
CachedFileListener.CreateContentId(contentId, destination),
ReadActivationMode.NotNeeded,
WriteActivationMode.AfterWrite,
CachedFileOptions.None);
deferral.Complete();
}
I'm overriding OnCachedFileUpdaterActivated(CachedFileUpdaterActivatedEventArgs args), but it never gets called (app crashes before here).
Again, it only crashes in WP10. Win10 works fine.
Note: sometimes it doesn't appear to crash, but the updater method is still never called.
I have also tried this sample here:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/FilePickerContracts
And I get similar results in that OnCachedFileUpdaterActivated is only ever called on desktop not phone.

how to debug wp8 app downloaded from store?

I've made a game using marmalade sdk and AppEasy engine and it works when I test it on the device but after submitting to store and downloading it only shows splash screen and then terminates.
Is there a way to debug it? Android and ios both have tools to trace the console output, is there such a tool for wp8? I only found how to do that for apps deployed to the device locally but no way to debug downloaded apps :(
For my other game made in same framework (with same issue) there is a crash report on the dev center dashboard with error saying 'STACK_OVERFLOW_DATA' but that doesn't help much
also tried this (solution found in some other question):
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
string result = "nothing :(";
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (store.FileExists("iwtrace.txt"))
{
using (var stream = new IsolatedStorageFileStream("iwtrace.txt", FileMode.Open, store))
{
using (var fileReader = new StreamReader(stream))
{
result = fileReader.ReadToEnd();
}
}
}
EmailComposeTask task = new EmailComposeTask();
task.To = "";
task.Subject = "crash log " + e.ExceptionObject.Message;
task.Body = result;
task.Show();
}
but it never get's to showing the email form
There's no way yet to debug retail version of WP8 apps especially which are made in Marmalade.
You can read more about that in the article explaining how to test the retail version.
According to the article you need to test the retail version via Visual Studio in case of Native C# app. I suppose even native XAML apps can't be debugged after downloading from store.
I've asked almost similar question on Marmalade forums last year. The only way at that time was to use Windows Power tool or Visual Studio.
To test the function, run your code from Visual Studio in release mode and see if it crashes or not. That's the only thing you can do in this case as far as I know.

Windows Phone 8 app crashes when redirecting between pages

I am developing a hybrid app which works fine on android and ios. But in windows, at times application crashes when redirecting between pages. I am getting following error messages in Visual Studio output window.
System.SystemException
Microsoft.Phone.Interop.ni.dll but was not handled in user code
It breaks the application at following point in App.xaml.cs.
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
I have no idea which part of code is causing this and I have never seen any such crash before.
Please throw some light on this issue!
Thanking you in anticipation!

Microsoft.Live.LiveAuthException: User has not granted the application consent to access data in Windows Live

Hello I'm writing Windows phone application for working with OneDrive. My code is pretty simple:
XAML:
<OneDrive:SignInButton Name="signInButton1"
Height="72"
Margin="152,436,144,0"
VerticalAlignment="Top"
ClientId="MYCLIENTID"
Scopes="wl.basic wl.photos wl.skydrive wl.offline_access wl.signin wl.skydrive_update"
SessionChanged="signInButton1_SessionChanged"
TextType="Custom" />
CS code:
private void signInButton1_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected)
{
Session = e.Session;
}
}
When I push drive sign in button Signin the window is opened and if i don't submit this window but instead just press the back button then the white screen is shown and I get:
An exception of type 'Microsoft.Live.LiveAuthException' occurred in
mscorlib.ni.dll and wasn't handled before a managed/native boundary
User has not granted the application consent to access data in Windows
Live
Could somebody help me with it?
Try upgrading to the LiveSDK 5.6, which was just released a week or two ago. In using a sample Windows Phone 8 app with your code, this exception appears to be handled internally and doesn't get thrown into the UI (aka, I can't repro this with Live SDK 5.6).

Geolocator.GetGeopositionAsync throw "Class not registered" exception c#

I run next code in blank project and got "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
private Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
var position = await this.locator.GetGeopositionAsync();
}
catch (Exception ex)
{
//Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
}
}
Also, I tried to run Geolocation Sample 8.1 (c# and JS) but got the same exception and I tried to run this sample not on 1 PC and not on 1 network. All the same.
I have win8.1 rtm and VS2013 RC on my laptop.
Also, I run this code and Microsoft sample on ARM tablet with 8.1 Pro preview (with GNSS module) and on tablet(i5-3317U Processor and without GPS module) with 8.1 rtm. I didn't get this exception and all works fine. So I think it only occured on PC/Simulator.
How to test GeoLocation app on PC/Simulator?
The code works, I tested this on my computer:
private async void Button_Click(object sender, RoutedEventArgs e)
{
var locator = new Windows.Devices.Geolocation.Geolocator();
var position = await locator.GetGeopositionAsync();
}
I tested both on Windows 8 with Visual Studio 2012 as well as Windows 8.1 (Preview) and Visual Studio 2013 (preview). As long as the capabilities were set there were no problems. I did not download the sample, the code is fairly straight forward to write even for complex scenarios. Look at the sample for inspiration, but code your own. Always easier not having to debug somebody elses logic :)
Code was tested 'on pc' as well as simulator (although there shouldn't be a difference since the simulator IS your PC as it remote desktop's to your own computer)
Make sure that you set capabilities for location:
Use the location option in the simulator to set a specific address if you want:
My breakpoint
If all fails, do the usual. Uninstall the app, clean and rebuild, restart computer and Visual Studio, and check that the location capability is set by using getting the charm bar once the app is installed and running, and select permissions. It should say that it has permissions, see below:
Best of luck!
Test this code on 8.0 - work fine.
On 8.1 rtm still got class not registered exception.
I think I need to add some library, but don't know where.
UPD:
I found where is problem.
I have Pro N version of win 8.1. In Pro N this code throw exception.
On Enterprise and Pro versions all work fine.
As said "zedkommander" above, error com from "N" version of windows 8.
But he didn't give the solution, so i'm going to give it :
Microsoft employee confirmed this problem :
This behaviour is indeed specific to the ā€œNā€ editions. For geolocation to work on N-editions of Windows, the Microsoft Media Feature Pack needs to be installed.
Geolocation has a dependency on WPD (Windows Portable Devices) infrastructure which is not present in N editions until the feature pack is installed.
If you want to fix it, you need to install "Microsoft Media Feature Pack" by clicking here : https://www.microsoft.com/fr-fr/download/details.aspx?id=30685