Facebook Connect / phonegap - "nativeInterface" parameter within FB.init call, what it does? - android

So I have been trying to run the Facebook Connect example for PhoneGap / Android with no luck.
https://github.com/davejohnson/phonegap-plugin-facebook-connect *
There are some similar threads with the same problem.. conclusion is that "Facebook SDK is a moving point"
I have succesfully compiled previously apps using phoneGap & Eclipse.
Now following the example* for Android. If I do exactly what they suggest. App shows the buttons but nothing happens when I click on them.
After analyzing the code I have noticed that
function initFB(){
try {
FB.init({ appId: "45253452345234523", nativeInterface: PG.FB });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}
there is a parameter nativeInterface : PG.FB which is nowhere described within Facebook API for this call..
http://developers.facebook.com/docs/reference/javascript/FB.init/
what is more interesting is that when i remove this parameter.. suddenly Login button goes to Facebook page with Error Code API 191.
So my question is what this parameter is supposed to do? and why it is not in Facebook API?
I have found no info about this parameter in internet. I guess if it would be a case of an out-dated FB API there would be some info available.
Any ideas?
Thanks,
Marcin

The "nativeInterface: PG.FB" option is to tell PhoneGap to use the native authentication interface instead of the mobile web interface. If you don't add in the "PG.FB" option, you'll get redirected to Facebook's mobile authentication instead. It took me a while to figure this out too, and it's not well documented, but that's what is going on.
Two other things about the PhoneGap Facebook Plugin that are not up to date with the latest Facebook JavaScript SDK:
When using FB.login() you should be using the "scope" parameter, but PhoneGap expects the deprecated "perms" parameter.
When the authentication response from FB.login() you should be getting "response.authResponse", but instead "response.session" is what is given back. This means you'll have to pull out the OAuth Access token with "response.session.auth_token" instead of "response.authResponse.accessToken".
Hopefully they'll get to updating the PhoneGap Facebook Plugin, but for now I use if/else statements to detect if PhoneGap is there. You can check if PhoneGap is initialized by using:
if(window.PhoneGap) {
//PhoneGap Library is Loaded
}

Related

How to specify the Redirect URI for React Native Bare workflow

I've just started building a React Native mobile application with Bare workflow(not using Expo framework).
I have successfully integrated the login and logout system on my app with react-native-auth0 dependency. However, I am struggling with API Authorization to get the token for the authenticated users in order to control the access to each end point.
I am following Authorization Code Flow with PKCE based on the Auth0 documentation. I've got almost everything working fine except the redirect uri which was mentioned earlier on the title.
I tried to use the expo-auth-session dependency to specify the uri manually like below.
const redirectUri = AuthSession.makeRedirectUri({
native: `${REDIRECT_URI}`,
useProxy,
});
const params = {
audience: `${AUTH0_API_AUDIENCE}`,
scope: ['openid', 'profile', 'email', 'offline_access'],
response_type: 'code',
client_id: `${AUTH0_CLIENT_ID}`,
redirect_uri: redirectUri,
code_challenge: `${code_challenge}`,
code_challenge_method: 'S256',
state: `${state}`
};
However, it returns the error message saying
Error: No default return URL could be found. If you're using the bare workflow, please provide options.returnUrl.
getDefaultReturnUrl#http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:179940:24
startAsync$#http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:177411:84
I have checked my uri with npx uri-scheme list.
at the moment, I've got one ${applicationId}://.
Would this be the equivalent to the redirect_uri, wouldn't it?
I've also have checked Auth0.Android.
However, this one must be related to Android Native App development?!
Anyway, anyone who has used the same architecture before? Where I can specify the Redirect URI for Android application built with React Native?
I think the AuthSession API is not supported in Bare workflow. Even though the documentation emphasised, it also articulates the walkthrough for the bare workflow, I gave it a shot. But, it's not working and thrown an error.
I believe this should be done in a native way?!? Java?? I am struggling to find the solution and not even sure where to look at. I would really appreciate your help! :-)
Disclaimer: I’m really not familiar with React Native (nor with mobile actually), but I do know a few things about OAuth and OIDC, and I used Auth0 in the past, so here a few ideas, hopefully helpful.
I have checked my uri with npx uri-scheme list. at the moment, I've got one ${applicationId}://. Would this be the equivalent to the redirect_uri, wouldn't it?
According to Auth0 documentation, the callback URL (i.e. the redirect URL to the local device) should look like {YOUR_APP_PACKAGE_NAME}://${YOUR_AUTH0_APP_NAME}.auth0.com/android/{YOUR_APP_PACKAGE_NAME}/callback
So my understanding is that ${applicationId}:// is not equivalent to the redirect URL, but only its prefix.
Have you tried using ${applicationId}://{YOUR_AUTH0_APP_NAME}.auth0.com/android/${applicationId}/callback
(replacing ${YOUR_AUTH0_APP_NAME} with the actual value of your Auth0 project name) ?

WeChat SendAuth request for access token code only works once

I am following the WeChat Login documentation for Android and it works but only once and I can't repeat the process.
I use this code to get the access token code:
IWXAPI api = WXAPIFactory.createWXAPI(this, APP_ID, false);
SendAuth.Req request = new SendAuth.Req();
request.scope = "snsapi_userinfo";
request.state = "wechat_sdk_demo_test";
api.sendReq(request);
I have created the WXEntryActivty and I received the response from the WeChat app and I can finish the login process.
But if I reinstall my app and try to login with WeChat again I always get ERR_BAN (-6) error code. To make it work again I have to reinstall the WeChat app.
I could't find anything about when can I get ERR_BAN error code in the documentation. Can anyone help me with this problem?
I had many problems using Wechat API and testing directly on wechat app on my phone due to CACHE.
It's very difficult to flush wechat cache, i would say almost impossible, that's why you have to re install wechat to start your tests again.
I highly suggest you to use the desktop testing app for wechat, download it here, links are in the end of the page:
https://mp.weixin.qq.com/wiki?action=doc&id=mp1455784140
Then you will be able to debug every step of your development AND flush cache. Additionally you can link the software to your phone and debug what happens inside wechat web browser.
I managed to solve the problem. I copied the MD5 signature directly from the keytool's output which is contains colons :. I removed the colons from the signature and now it works correctly.
I think this is a bug in the WeChat app because the signature works with colons when the app displays the authorization page but not after that.

Change in twitter login

As we know, there have been changes in access to the twitter API referring to callbacks URLs.
So far, I have been using the identification callback with firebase, as I indicated here:
This has been working perfectly so far.
I read in the documentation that now you have to indicate the callback, according to android or iOS in the following way:
twitterkit- : // if using Twitter Kit for iOS or
twittersdk: // if using Twitter Kit for Android.
My application is only developed for android.
I have tried all the possible variants, but I always get the following error:
The client application failed validation: Not a valid callback URL format.
The tested options have been:
twittersdk://pfa89MGYola62VIln ........ (MY_CONSUMER_KEY)
twittersdk://MY_APP-android.firebaseapp.com/__/auth/handler
twittersdk://https://MY_APP-android.firebaseapp.com/__/auth/handler
I have activated and deactivated the check "enable callback locking" ...
I've tried everything, I'm a little desperate
For another test, I tried to register the URL callback as if it were the iOS platform
twitterkit-MY_CONSUMER_KEY://
and it was accepted on the first attempt.
I do not mind losing the relationship with firebase, the truth is that I was not using it, but I have a serious problem if I can not connect with twitter again.
I appreciate any help.
I found the solution, I put it here in case it can be of help to someone.
The truth is that it is not well specified in the documentation, you have to take two steps.
First: activate the "enable callback locking" checkbox
Second: indicate the android sdk for twitter, WITHOUT CONSUMER KEY, unlike iOS users.
It would be like this:
I hope it helps

Trying to use openFB with Cordova

So i´m having a situation that someone might be able to help.
Im creating a Mobile APP using PhoneGap Build. I´m trying to use this http://coenraets.org/blog/2014/04/facebook-phonegap-cordova-without-plugin/
Right know if I open the app inBrowser it will work. Ask's for permissions etc and fetch the user data correctly. Of course I defined a Valid oAuth: localhost/...html.
So it works for browser but doesnt work for mobile. Wich should be, if so, the valid url for the mobile? Cause since it's an APP iºm confused. I dont think it's necessary show code but if so just ask me.
Thanks ;)
You can still use openFB and it will work. you don't even need to change anything in the openfb.js file. all you have to do is manipulate the call method from the page where you want to call the facebook login window.
say for example you have the facebook call method in index.html
then add this script to that index.html page where the function "facebooklogin()" is called
<script>
openFB.init({ appId: 'your-app-id' });
function facebooklogin() {
openFB.login(function (response) {
if (response.status === 'connected') {
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
openFB.api({
path: "/{your app version in facebook developer envi.}/me?",
params: { "access_token": accessToken, "?fields":"name,email,gender,user_birthday,locale,bio&access_token='"+accessToken+"'" },
success: function (response) {
var data = JSON.stringify(response);
// do whatever you want with the data for example
$(".data_div").html(data);
$(".data_email").html(data.email);
},
error: function(err){
alert(err);
}
});
}
else {
alert(“empty response returned”);
}
}
else {
alert(“not connected”);
}
},
{
scope: "public_profile,email,user_birthday"
});
}
</script>
very important! Please replace {your app version in facebook developer envi.} with your app version like v2.0 or v2.5
also don't forget to change 'your app id' to you facebook app id example 432046826485152
with openfb you don't need to crack your head over learning hoe to configure facebook login in other platforms. this will serve all platforms
I've got it working on the phone.
The weird thing is that a real URL is not necessary, just a semantic valid one. I've added a Facebook Canvas platform, on the facebook app page, and filled the platform form:
URL = http://localhost/www/
Secure Canvas URL = https://localhost/www/
Both of above domains doesn't exists. I haven't filled the "Valid OAuth redirect URIs" field in the advanced tab.
After that, I've written the following code in my app:
openFB.init("xyz!##123456789"
, "http://localhost/www/oauthcallback.html");
It seems that what matters is that Facebook Canvas's domains or sub domains matches the one on the openFB.init redirectURL param...
I'm using openFB version 0.1. I'm gonna test the earlier versions.
UPDATE
It just have worked because I was using phonegap serve and it makes openFB understand that my app is a website, because phonegap developer app is a browser wrapper, not a app wrapper. If I try to run it in a compiled app (phonegap local build), my code doesn't work. I think I'll have to use facebook-connect earlier than I thought...

Phonegap ChildBrowser Issue

I am creating a mobile app which connects to some jive based community using childbrowser.
I can easily open the community, login and do stuff.
But I also need to fetch session details in my app, so that I could use these to fetch JSON strings to show user image/info on my app showing that user is logged in.
I tried working on childbrowser, but couldn't investigate much.
It seems it won't work with my community URL. While using google url it shows popups on location changes, but not for my url.
Can any one help me in fetching the data I want ?
Here is the sample code I am using to detect location change:
function openURL() {
window.plugins.childBrowser.onLocationChange= function(loc){
alert('In index.html new loc = ' + loc);
};
window.plugins.childBrowser.showWebPage("https://communityName.jive-mobile.com/#jive-login", { showLocationBar: false });
}
I am getting my login page, but after login I can't see any alert coming !!
I need to get proof of user login and user session details.
Thanks
I have just updated the ChildBrowser plugin for my own use, following code given here: How do I get the web page contents from a WebView?
I am using this to log in on Google API oAuth2, watching for the right page to load. I am using the onPageLoaded(html) event that has the (computed) html source. You might want to use this to get the html that was loaded and check for "stuff". I don't use jive so I wouldn't know where to start, but I'll put up a sample Google oAuth2 project for you to try.
HTH
EDIT:
the code is at: https://code.google.com/p/filechunkreader/
Don't let yourself get fooled by the name, this project is the repo for my Java plugins experiments. It contains so far 2 plugins, FileChunkReader and a custom version of ChildBrowser.

Categories

Resources