Facebook OAuth Unable to Connect - c#

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).

Related

Adding Authentication to UWP apps with Azure Mobile App as backend

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.

Google Account login Integration for android Xamarin

I need to integrate google login to android xamarin application.
gone through the code from bellow link:
http://motzcod.es/post/67077106339/google-plus-services-login-and-1-in-xamarin-android
it shows the error connection failed and [GooglePlayServicesUtil] Google Play Store is missing.
even ofter adding google play service(Froyo) component.
even i gone through the bellow links
https://developers.google.com/+/mobile/android/sign-in
Android: Login using google account?
Google Login For Android App
but this is related to android eclipse using java code.
can anybody suggest me how to do this in xamarin. any hints/links are appreciated.
thank you.
Finally i got a solution by doing the research over the available codes from xamarin forum and stackoverflow.
I made use of the OAuth2Authenticator
Register in google developer console as webapplication instead of installed application(android)* provide the redirect url with valid url ("http://abcd.com/xyz.aspx") same should be used in the application code.
On authentication complete it will return access_token
By using the access_token make the REST request to get user complete information (https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessTokenValue + “.)
Deserialize the json response to get information in object.
*If we registered in developer console as installed application(like
android) after making OAuth2Authenticator request it will show window
with message please copy this code switch to your application and
paste it there [code] manually need to close the window and proceed
to authentication. to get ride of this webapplication type is choosen.
Refer for more info. : Login by google account integration for Xamarin.Android and Xamarin.iOS
The answer given is great. It works without trouble so long as that redirecturi is a real and accessible url for the underlying WebView to connect to at the end of the flow. In a mobile scenario this really doesn't make sense but google requires it. The examples typically say use localhost as the redirecturi which leads to a 401 UnAuthorized response showing in the UI. Ugh. Authentication is successful, but you have this ugly box you have to click on.
My solution on this was to have the redirecturi be the me link, https://www.googleapis.com/plus/v1/people/me. The code you have completes, there are no errors and the view is dismissed. Hope this helps somebody.

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.

Windows Phone in-app products

I've started creating a C# Windows Phone (Silverlight) app. I would really like to include in-app products. I've followed the tutorial: Tutorial
I've managed to add all the in-app products to my app. Just to test it, I've added a free in-app product. But when I click the download button in my app, I get an error message. My code is exactly the same as the above tutorial at the moment. I will change the code after fixing this error.
Error message
Service not available
The Store isn't available at the moment.
Please check back in a bit.
Inquiring minds may find this error code helpful: 805a01f4
I've googled the error code. According to the Microsoft website, I have to try again later. I've been trying for 3 days. But I am able to download apps from the store.
What I'm I doing wrong?
some people solved the problem by changing the APP-ID in the AppManifest.xml and WMAppManifest.xml to the one given in the dashboard.
http://social.msdn.microsoft.com/forums/windowsapps/de-de/79e81def-39f4-4465-abad-d4c484f099ef/users-reporting-error-code-805a01f4-when-trying-to-buy-inapp-purchase?forum=wpdevelop
For me this solution didn't work, but maybe for you?

"An error occurred. Please try later" trying to connect to Facebook (Windows Phone/C# SDK)

((Using the C# Facebook SDK))
I have an app that's been working for a while now.. Since a few months ago, when people started getting Windows Phone 8 devices, some people have been getting an error when trying to connect the app to Facebook. I have not been able to get a clear repro on which devices/combo this happens for sadly, though it seems like it's more than one device and it seems to be happening on 7.5 devices as well.
The error some are getting is "An error occurred. Please try again." after putting in their name/pwd. I have added some debugging code and have the page content (minus pwd) they are seeing and it's just a blank page with the error at the top. The navigation that occurs on the hosted browsers is this (client_id replaced to protect my key, but I validated that it's correct).
First they get this:
https://www.facebook.com/dialog/oauth?response_type=token&display=touch&redirect_uri=http://www.facebook.com/connect/login_success.html&client_id=XXXXXXXXX&scope=friends_birthday,offline_access,publish_stream,user_photo_video_tags,friends_photo_video_tags,user_photos
Then they get redirected to this which gives the aforementioned error:
https://m.facebook.com/dialog/oauth?response_type=token&display=touch&redirect_uri=http://www.facebook.com/connect/login_success.html&client_id=XXXXXXXXXX&scope=friends_birthday,offline_access,publish_stream,user_photo_video_tags,friends_photo_video_tags,user_photos
Note that there's another class of users that are seeing a different behavior (those with 7.5 devices, I think).. They go to the same page as the previous ones, and then redirect to an empty page (when I look at the content, there's "error" at the title, but the page is otherwise empty.
I am unable to repro this on either of my devices or the various emulators (8.0/7.5 etc).
Does anyone have an idea on how to debug this?
I had the same problem, but with a different setup
login to my website via desktop browser was working,
but login via mobile browser failed with "an error occured, please try again"
I saw the problem on an old (2.2) android and an old ipod touch
I could fix the problem, by sending the user directly to the https://m.facebook.com/dialog/oauth?... page, if he was on a mobile browser.
Users on desktop browsers still will be send to https://www.facebook.com/dialog/oauth?... page.
I am an idiot. Somehow, the app transitioned to "Sandbox mode" and thus allowed only developers to use it.

Categories