Adding Authentication to UWP apps with Azure Mobile App as backend - c#

I am working on UWP app which requires users to login using social identity providers like Microsoft, Google etc.
I have followed the quickstart guide here which describes how the authentication can be added.
In the UWP Quickstart app the installed version of Microsoft.Azure.Mobile.Client is 3.1.0, if I upgrade this to the latest version i.e. 4.0.0, an error is thrown on the line LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount) that LoginAsync has no overloaded methods that take 1 argument. To resolve this I added a SingleSignOn parameter to the method which is a boolean
var user = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, true);
When I run the application the Microsoft login popup is shown successfully, however when the users logs in, the popup does not go away and control never returns to the app. Following is the screenshot:
If I close the popup manually then an exception is thrown :
Authentication was cancelled by the user
So is this a Microsoft.Azure.Mobile.Client Nuget package version issue or am I missing something here.
Any help would be much appreciated.

Ok, I'll answer to you question now, because I was able to solve it just a couple seconds ago.
So you are using UWP, I'm using Template 10 and I've been able to make it work on both, firstable update to v4.0.0 or v4.0.1 according to what i found out was because google authentication stopped allowing web views for authentication and the concern for Azure-Mobile-Net-Client team was that all OAuth provider would adopt that behavior in the future base on an article that you can find here if you are interested:
Modernizing OAuth interactions in Native Apps for Better Usability and Security
after this being said we are in the middle of a big change here, so in order to make it work you need to set your mobile app service to allow external redirects using url_scheme_of_your_app as shown on microsoft documentations tutorial.
So the step are the next ones:
1.- Go to Azure Portal
2.- Go to your MobileApp Service
3.- Choose Authentication/Authorization
4.- at Allowed External Redirect URLs write this: {urischeme}://easyauth.callback
(meaning that urischeme must be alphanumeric word beginning with a letter).
5.- Save changes.
Now after you have done that now you gotta work on your client
then if you are using UWP follow this tutorial:
Add Authentication to your UWP.
and that should be enough, if you are using template 10 all you gotta do is at OnStartAsync Method use this code:
if(startKind == StartKind.Activate)
{
ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;
cloudService.ResumeWithUrl(protocolArgs.Uri);
}
you saved tons of code at the tutorial because you gotta write code at OnNavigatedTo() Method and at OnActivated() method at App.Xaml.cs
thats for the architecture in UWP and at Template 10 that acts like a wrapper of Application class and simplifies its usage.
Hopefully this helps you, also you will notice that when you first sign in at your app using urischeme it opens your default browser and stays open after successfully logged in.
Also singlesignon overload method doesnt work at all yet, they are still working on those issues.
hopefully my answer helps you!!!

I just wanted to add my solution for xamarin.forms on uwp, which should be actually same as we are doing redirecting and login on native level. I followed this article https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-users
but there was something confusing about url scheme of your app part when you define the return url.
Basically you define return url in 4 places and they sound like the same but they are different
1) you define on facebook developer page. it should (use https) https://myapi.azurewebsites.net//easyauth.callback
2) on the azure portal for allowed external redirect urls
add here 2: https://myapi.azurewebsites.net//easyauth.callback, myapp//easyauth.callback
3) uwp package manifest- declaration. add myapp as name
4) Login call to azure mobile services: Client.LoginAsync(provider, "myapp");
So basically myapp (this is name you choose) should be available in azure portal and same name used in your uwp project. otherwise even login is successful, you end up with this screen instead of redirected back to the app.

Related

Facebook OAuth Unable to Connect

I have been trying to create an iOS App using Xamarin (i.e. using Xamarin.iOS on C#) and I have run into an error I can't seem to resolve.
Basically, I have entered all the (correct) details into the default Facebook iOS SDK object as directed in the sample documents. However whenever I click login, the page returns 'unable to connect to server'.
The (URL Decoded) link the SDK sends me to is listed below:
https://m.facebook.com/v2.3/dialog/oauth?client_id=(ID-REDACTED)&default_audience=friends&display=touch&e2e={"init":REDACTED }&redirect_uri=fb-ID-REDACTED://authorize/&response_type=token,signed_request&return_scopes=true&scope=&sdk=ios&sdk_version=4.2.0&state={"REDACTED":"REDACTED= ","0_auth_logger_id":"REDACTED","com.facebook.sdk_client_state":true,"3_method":1}
Pointing to this in a browser returns me to a blank page (when I enter in my ID which I have removed from the link above). I'm pretty certain this is due to an error in the way I have set up my application on Facebook as opposed to an error with the SDK (I'm using the default provided by Xamarin). I have removed the app from Sandbox Mode as directed and I have tried to follow the instructions provided on a couple of forum posts but nothing has changed and I am at a loss right now...
Any advice?
Thanks!
Turns out I've managed to solve my issue...
For some really odd reason, m.facebook.com and facebook.com were added as entries in the hosts file (meaning that they were essentially blocked domains). This was weird given that I could access facebook from standard browsers like safari/firefox (just not the safari browser in the simulator).
If you have a similar issue, please change the hosts file (follow some tutorials online).

FacebookSessionClient Given URL is not allowed by the Application configuration

I'm developing a Windows 8.1 Store Apps with .NET Framework 4.5.1, C#, Facebook 6.8.0 SDK and Facebook.Client 0.9.1-alpha.
Probably I'm not doing it well, but I want to add Facebook Login to my app, and to do it, I'm following this tutorial: Facebook Scrumptious tutorial for Windows 8 (I think it is out of date).
This is my code:
private async Task DoFacebookLogin()
{
session = await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream");
Debug.WriteLine(session.AccessToken);
Debug.WriteLine(session.FacebookId);
}
I'm using FacebookSessionClient to do a login, but I get this message:
The application configuration does not allow the URL provided .: One or more
of the URLs you provided are not permitted by the application configuration.
Must match the URL of the website or the URL of the main page of the application,
or domain to be a subdomain of one of the application domains.
Can I use FacebookSessionClient on a Windows 8.1 Store app? I think it is only for web applications.
Meanwhile I'm going to test this tutorial. Here they use WebAuthenticationBroker.
so I had the same code sample work just fine until recently. I believe that you have to go into Facebook and enter your ID for your app. once that information is available, then FB will know your app and stop throwing those exceptions. I'm in process of verifying right now.

Unable to add multiple redirect URLs with Microsoft Live OAuth service

I have an ASP.Net C# Web Application in which I have added Windows Live oAuth authentication (I am not using the code supplied by the Visual Studio project template for oAuth). I have two return pages in my application where the user should come back after authenticating with the Windows Live oAuth Service. The reason I have two end points is to distinguish two different modes in my application based on where the user returns.
Anyways, the problem is that when I add the second URL in the configuration screen of Microsoft Windows live at https://account.live.com/developers/applications/apisettings/, the Microsoft Live page simply does not save it. Here is what I am doing:
Go to https://account.live.com/developers/applications/index
Click Application name and then edit Settings
go To API Settings
Click "Add another redirect URL"
Added my second URL and clicked save.
The second text box where I entered the URL simply disappears and my second URL does not work in the oAuth flow.
If any of you has faced a similar issue, do you have a work around? If this is something Microsoft should fix, where should I raise this bug with Microsoft?
Update: I have also tried a work around of creating two applications, so that each one has one of the return URLs, but Microsoft does not allow two applications with the same root domain URL. :(
I have the same issue.
This is not your fault, and there is nothing other than Microsoft would be able to fix it.

azure acs authentication in winrt

I'm trying to authenticate users in a winrt metro app using Azure ACS.
I've set up a relying party in azure with a simple webtoken.
on windows 8 I've installed the azure toolkit. When I created a new project from the winrt cloud (notifications + acs) template and I fill in all necessary parameters I can run the app, I get the live ID login screen but when I enter my credentials I get a message saying "We can't load that page".
Can anyone help me with this?
With "I fill in all necessary parameters" I'm assuming you mean the Configuration.xml file contains the necessary information to your ACS namespace etc...
Now, filling in this information and configuring ACS isn't enough to make the sample work. If you take a closer look at the Configuration.xml file, you'll see the following elements:
<!--Relying party return Url. The bouncer service url that will parse the token from ACS.-->
<ReturnUrl>https://127.0.0.1/bouncer</ReturnUrl>
<!--Authentication End Url. The bouncer service url used to validate if the authentication process is done.-->
<EndUrl>https://127.0.0.1/bouncer/end</EndUrl>
These are URLs from an Azure application you'll also need to run in order for the sample to work. In the toolkit you'll find the following directory:
WATWindows.Setup.v1.2.4\Samples\Notifications.CSharp\Notifications.Backend
To be able to run the sample application you'll need to start this backend application first.
And did you already run the SetupSample.cmd script in the WATWindows.Setup.v1.2.4\Samples\Notifications.CSharp directory?

share a message in Linkedin via windows phone

want to share a link from my application in windows phone 7. Any one know a good API library for this.....I have downloaded a API from a site which shows null information like this
Usage
1. Create a button that sends the user to a page where the login process will start like LinkedInBeginAuth.aspx or Account/LinkedInBeginAuth in MVC
2.Inside LinkedInBeginAuth Page add the following code
Create the page that the user will be redirected after login
Inside that page add
5.That's it!
Library is in EARLY development so expect major changes. Use it wisely.
Have you looked at the ShareStatusTask :-
http://msdn.microsoft.com/en-us/library/hh394027(v=VS.92).aspx
If you want to use the LinkedIn API you'll need to connect via OAuth. (You can do this with Hammock & a WebBrowser control.)
Once connected you can call their REST API.
Alternatively, or possibly as a starting point, you could look at http://linkedintoolkit.codeplex.com/ but it doesn't look complete.

Categories