Authentication failed with Azure Active Directory in Windows Phone - windows

I am follow the window phone authentication tutorial with Add authentication to your Mobile Services app. And I choose using Azure Active Directory way to make authentication. But the question is: it always fails and shows The remote procedure call failed. (Exception from HRESULT: 0x800706BE) at the following code
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
await Authenticate();//here throws System.Exception in mscorlib.ni.dll
await RefreshMissionTable();
}
And I make sure there is nothing wrong in my Azure setting. The weird thing is that when I choose windows phone universal app sample, and do the same procedure again, it can work in the windows 8.1 emulator! But still can't work in the windows phone 8.1 emulator .
And the break point stays here
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
}
}
}

this might be related to a known problem with the WebAuthenticationBroker on Windows Phone 8.1: it cannot be invoked until the full UX of the app has been loaded. Please take a look to this thread for a description of the issue and proposed workarounds: https://social.msdn.microsoft.com/Forums/vstudio/en-US/95c6569e-2fa2-43c8-af71-939e006a9b27/mobile-services-loginasync-remote-procedure-call-failed-hresult-0x800706be?forum=azuremobile
HTH
V.

Related

Xamarin BluetoothLE Plugin not working

I created a new Xamarin.Forms app to test basic Bluetooth functionality. I downloaded this plugin into both the Android project and the shared project:
https://github.com/aritchie/bluetoothle
I wrote this function in the shared project and am calling it from the OnCreate of my launch activity in my Android project:
public static async Task BroadcastBluetooth()
{
// (I do not await this function when I call it)
try
{
await Task.Delay(5000); // just to make sure we give enough time for all initialization to complete
_server = CrossBleAdapter.Current.CreateGattServer();
// exception thrown on this line
await _server.Start(new AdvertisementData
{
LocalName = "TestServer",
ServiceUuids = new List<Guid>()
});
}
catch (Exception e)
{
}
}
It throws this exception:
{System.NullReferenceException: Object reference not set to an
instance of an object. at
Plugin.BluetoothLE.Server.GattServer.StartAdvertising
(Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00095] in
C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:135
at Plugin.BluetoothLE.Server.GattServer.Start
(Plugin.BluetoothLE.Server.AdvertisementData adData) [0x00011] in
C:\dev\acr\bluetoothle\Plugin.BluetoothLE.Android\Server\GattServer.cs:70
at App2.App+d__7.MoveNext () [0x00097] in
C:\Projects\app2\App2\App2\App.xaml.cs:49 }
I'm only doing something really basic so I must be missing something? The exception is referencing a directory path of the plugin's developer's machine (C:\dev\acr...) so either this plugin is broken or I'm doing something really wrong?
I am using the same plugin in a current project of mine and it is working fine. So I doubt the issue is within the plugin.
Some thoughts about what could cause the issue:
Are you testing this code on a real device that is capable of performing BLE Advertisement?
Do you have set the permissions accordingly in your android project?
Does BLE Advertising work when you use the native android apis?
It also would be helpful, if you could attach a repository with which I can reproduce the issue.

Windows Universal App Open webbrowser with link

I am making an universal app and when i click a certain button, i need to open the webbrowser with a link. I got the link as a string in a variable but the windows 7 / 8 app ways such as "Proces" and Webbrowser objects give errors.
In windows apps, you can't simply open other apps/programms.
The only posibility is to use the Launcher:
Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.google.de"));
The Launcher looks up the default program/app which is assosiated to the uri-scheme (in this case "http://" for webbrowsers) and forwards this call
others then above you can go Package.app manifest change the start page to the URL that you want or another method by using web control set the source to the URL you needed.
use scope async, it will open link to the mobile,PC default default browser for UWP
private async void Button_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.fmradiotune.blogspot.com"));
}

Issue with ADAL in windows Universal Apps

I'm building Universal Application,I'm using Azure Active Directory for authentication. I'm using Microsoft.IdentityModel.Clients.ActiveDirectory for SSO. for both Windows 8.1 and Window 10 store App. I've been referring to following URL for connecting to my Azure Active Directory and authenticating user
http://www.cloudidentity.com/blog/2014/08/28/use-adal-to-connect-your-universal-apps-to-azure-ad-or-adfs/
public login()
{
this.InitializeComponent();
redirectURI = Windows.Security.Authentication.Web.WebAuthenticationBroker.
GetCurrentApplicationCallbackUri();
authContext = new AuthenticationContext(authority);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// When the app starts, fetch the user's To Do list from the service.
GetTodoList();
}
private async void GetTodoList()
{
AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.windows.net", "e11a0451-ac9d-4c89-afd8-d2fa3322ef68", new Uri("http://li"));
if (result.Status != AuthenticationStatus.Success)
{
if (result.Error == "authentication_canceled")
{
// The user cancelled the sign-in, no need to display a message.
}
else
{
MessageDialog dialog = new MessageDialog(string.Format("If the error continues, please contact your administrator.\n\nError: {0}\n\nError Description:\n\n{1} {2}", result.Error, result.ErrorDescription, s1), "Sorry, an error occurred while signing you in.");
await dialog.ShowAsync();
}
return;
}
I replaced clientID, authority and resource url according to my project. When I run Application from Windows phone , it works perfectly. When I run the same code in Windows 10 and same logic ported in windows 8.1 , Application prompts for user id and password,after entering these credentials I'm getting following error
"We can't connect to the service you need right now. Check your network connection or try this again later"
I see in the output windows of Visual Studio 2015 while running application as below.
"The type 'Page' is defined in an assembly that is not referenced. You must add a
reference to assembly 'Windows.Foundation.UniversalApiContract,
Version=1.0.0.0, Culture=neutral, Pub
The type 'IUICommand' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.UniversalApiContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'licKeyToken=null,
ContentType=WindowsRuntime'. "
I also tried to test same windows store on Windows 8.1, even their also it fails to authenticate User.
I have added all the capabilities like internet and intert client server
Add the following to config.xml:
<preference name="adal-use-corporate-network" value="true" />
The value is false by default.
More info here:
https://github.com/AzureAD/azure-activedirectory-library-for-cordova
this issue got resolved by adding useCorpnetnetwork = true for authenticationcontext along with changes in manifest like internet,internetclientsever,shared certificate . I missed shared certification in package

restrict the windows phone app for specific devices

i want my application should work on specific devices\OS like "Lumia 650"\"windows phone 8", this is my project requirement.
Is it possible ? if yes where should I mention the details ?
It is not a problem to restrict Windows Phone 8. You just need to build it targeting Windows Phone OS 8.0.
For the device model you do something like this in the App.xaml.cs
private void Application_Launching(object sender, LaunchingEventArgs e)
{
var deviceName = DeviceExtendedProperties.GetValue("DeviceName").ToString();
if (!deviceName.Contains("Lumia_650")) // Please check your phone's actual value
Application.Current.Terminate();
}
If you want to show a friendly message before it exits you can move the code to the MainPage.xaml.cs then add the MessageBox.Show(message) part.
This is only possible in code as you can not prevent users from installing the app if the app is meant for that particular OS what that user has. However, once the app is launched you can get the name of the device and do actions accordingly.
You can try this:
var PhoneName = Microsoft.Phone.Info.DeviceStatus.DeviceName;
if(PhoneName == "Not Allowed Phone")
{
MessageBox.Show("You can not use this app");
}
else
{
}

Windows Phone open another application

I need to open a new application from my application. If it is not installed on the phone then I need to open the installation inside windows store.
Anybody have an idea how can I achieve this?
I read the below articles but I couldn't find anything helpful:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207014%28v=vs.105%29.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987%28v=vs.105%29.aspx
Answer:
For the store i ended up using:
private async void test()
{
try
{
Uri uri = new Uri("zune://navigate/?appid=xxx-xxx-xxx-xxx");
await Launcher.LaunchUriAsync(uri);
}
catch (Exception exception)
{
//TODO
}
}
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662937(v=vs.105).aspx
describes how you can launch the store app and display a specific app
What you need will look something like this:
Windows.System.Launcher.LaunchUriAsync(new Uri("zune:navigate?appid=[app ID]"));
where '[app ID]' needs to be replaced by the unique app id of the application you want to install.

Resources