Facebook authorization using OAuth 2.0 PHP not working in ie and safari - facebook-php-sdk

I m developed a app for a photo contest.
steps:
the user authorize the app where i get the permission to get the photos and email.
Intro page and choose from facebook link
Photo's page where all of the users facebook photos are shown to choose. the user select one photo and click next
form to fill in and submit.
thankyou page with the photo selected.
In this app, my canvas url is "http://mysite.com/index.php?" where i authorize the app.
so when the user click "choose from facebook" link it redirects to another page where i display the photos.
In this page(photos.php) i use the below code same as in the index.php,
require 'src/config_app.php';
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => true
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
but i get the fatal error as below :
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in var/www/vhosts/mysite.com/httpdocs/src/base_facebook.php on line 1107
This happens only in ie and safari, i checked my chrome and firefox which is good.
I almost finished my app with using chrome and now stuck with this major issue in other browsers.
Am i doing anything wrong !?
Kindly help.
Many thanks.

Related

Deep Link doesn't open the app instead does a google search

I have been using Expo to develop a react-native app, The functionality I am currently trying to implement is to share a link with friends on platforms such as fb messenger/whatapp or even normal texts and when they click this link it will launch my app to a specific page using the parameters.
After extensive research online - I’ve come to a blocker, following expo’s documentation I defined a scheme for my app - when I press share everything works correctly a message is created and I’m able to share content but only as string.
I am using react-natives Share library to share to an app and I’m using Expo to provide me with the link.
Ideally my first goal is to get the app opening using the Expo Link before I explore further into adding more functionality to the link.
Share.share({
message: "Click Here to View More! " + Linking.makeUrl( ' ' , { postkey : "7a5d6w2x9d6s3a28d8d});
url: Linking.makeUrl( ' ' , { pkey : gkey });
title: 'This post is amazing',
})
.then((result) =>{
console.log(result)
if(result === 'dismissedAction'){
return
}
})
.catch((error) => console.log(error))
In the root of my app I have also defined the event handlers: App.js
_handleRedirect=(event)=> {
let {path,queryParams} = Linking.parse(event);
Alert.alert(`queryparams : ${event} path : ${path} `)
this.props.navigation.navigate("Post_Detail",{key:queryParams.postkey})
}
}
componentDidMount() {
let scheme = 'nxet'
Linking.getInitialURL()
.then(url => {
console.log("App.js getInitialURL Triggered")
// this.handleOpenURL({ url });
})
.catch(error => console.error(error));
Linking.addEventListener('url', ({url}) => this._handleRedirect(url));;
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
When I share the link to Whatsapp, Facebook Messenger or even just messages or notes it appears as myapplink://, I try to enter this into the browser and instead of asking me to open my app - it does a google search.
Please note I am attempting to have this working on Android Device and facing this issue
Is there something I am doing incorrectly?
Any help is much appreciated. Thanks.
You can not open external links, means other than http, https on Android. But you can on iOS. In order to be able to open your expo links, you need proper anchor tags on android. You can create html mails and give it a try, you will see it is gonna work on Android as well.

How to know if firebase.messaging().requestPermission has been previously called using react-native-firebase

I have a React Native app that uses Firebase Cloud Messaging with the react-native-firebase package.
I am doing this on the first screen of a React Native app, so after 5 seconds, the user will be sent to a new screen which explains why push notifications are useful, and gives them a button to launch the dialog where they can accept or decline the permission.
setTimeout(() => {
firebase.messaging().hasPermission()
.then(enabled => {
if (enabled) {
// user has permissions
} else {
// user doesn't have permission
this.props.navigation.navigate('EnableNotificationPermissionScreen')
}
});
},
5000);
In the EnableNotificationPermissionScreen screen, there is a button like this:
<Button onPress={this.onSetNotificationPref.bind(this)} title="Set Notification Preference" color="#4ab2fc"/>
Which is handled by an event like this:
onSetNotificationPref() {
firebase.messaging().requestPermission()
.then(() => {
// User has authorized
firebase.analytics().logEvent('messaging_permission_accepted');
this.props.navigation.navigate('App');
})
.catch(error => {
// User has rejected permissions
firebase.analytics().logEvent('messaging_permission_rejected');
this.props.navigation.navigate('App');
});
}
If the user accepts, everything works as I would hope, and the user will have the permission, and will not navigate to that screen again.
However, if the user rejects the permission, I do not want to navigate them to that screen again. As-is, they will be navigated there again because hasPermission will be false. Also, clicking the button to execute requestPermission on that screen will do nothing, as the OS will block requestPermission().
In the examples I have seen, requestPermission is called whenever the permission is not enabled (with no custom screen like this); and so either the dialog pops up, or it doesn't. However, in the flow that I am trying to achieve, I want to navigate to this custom screen only if the user does not have permission because they have not been asked. If they have been asked and declined, they should not be navigated to that screen.
Is there any way to achieve that using the functions in firebase.messaging(), or do I have to use persistent storage like async-storage to track on my own whether the dialog has been shown?

Redirect to a page after authentication

After authenticating a user, how can I redirect them to a dashboard. How would it be customized with information about each user, and not information hard-coded onto a page? How does this relate, if at all, to getRedirectResult? Thanks.
You'll typically listen to onAuthStateChanged() for that. Whenever the user authentication state changes, your handler will get called and you can act on the new state. E.g.
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in so redirect to dashboard
} else {
// No user is signed in, so show login page
}
});

Displaying form on first login

I'm trying to work out how I can display a form to a user upon their first login to my app ( to fill in profile information) after which they can proceed to the regular site.
Could anyone point me in the right direction?
Thanks
You can make the trick using app startup script:
https://devsite.googleplex.com/appmaker/settings#app_start
Assuming that you have Profile model/datasource, code in your startup script will look similar to this:
loader.suspendLoad();
var profileDs = app.datasources.Profile;
// It would be more secure to move this filtering to the server side
profileDs.query.filters.UserEmail._equals = app.user.email;
profileDs.load({
success: function() {
if (profileDs.item === null) {
app.showPage(app.pages.CreateProfile);
} else {
app.showPage(app.pages.HomePage);
}
loader.resumeLoad();
},
failure: function() {
loader.resumeLoad();
// your fallback code goes here
}
});
If profile is absolute must, I would also recommend to enforce the check in onAttach event for every page but CreateProfile (to prevent navigation by direct link):
// Profile datasource should be already loaded by startup script
// when onAttach event is fired
if (app.datasources.Profile.item === null) {
throw new Error('Invalid operation!');
}
I suggest checking the user profile upon login. If the profile is not present, display the profile form, otherwise, proceed to the regular site.

FatFree basic auth, reroute on cancel

How to make FatFree reroute to whatever page I want it to, if user clicks on CANCEL button, when basic auth dialog appears?
I tried with -
if (! $auth->basic()){
$this->f3->reroute('/');
}
but this doesn't work. Page is shown with message:
Unauthorized
HTTP 401 (GET /protected-url)
reroute in the $f3 bootstrap index.php can be used like this:
//logoutfrom forum
$f3->route('GET /logout',
function($f3)
{
$f3->clear('SESSION');
session_commit();
$f3->reroute('/loggedout');
//where loggedout is a view
}
);
Also i was going to use basic auth but in fact found the none basic better; you an then just use something like:
if ($f3->get('SESSION.user_name')== NULL )
{
$f3->reroute('/inform/notauthorised');
}
//where notauthorised is a view

Resources