Django-allauth: FB connect working with oauth2, but not with js-sdk - django-allauth

I'm trying to connect to FB using django-allauth. Earlier I went with the oauth method and it was working fine, get all the access tokens. But now, I'm trying to run with js_sdk, but cant figure the problem here.
settings.py:
SOCIALACCOUNT_PROVIDERS = \
{ 'facebook':
{ 'SCOPE': ['email', 'publish_stream','user_birthday'],
'AUTH_PARAMS': { 'auth_type': 'reauthenticate' },
'METHOD': 'js_sdk' ,
'LOCALE_FUNC': lambda request: 'en_US'}}
html:
{% load socialaccount %}
{% providers_media_js %}
Facebook connect
On clicking the Fb connect link, nothing happens as it tries to make a call to javacript:FB_login(''), which doesn't work.
Any help on this would be great. Thanks!

Placement is important. It's recommended to include this right after your < body > tag.
{% load socialaccount %}
{% providers_media_js %}
To slim down to barebones settings for testing, you could also try this:
SOCIALACCOUNT_PROVIDERS = {
'facebook':{
'SCOPE': ['email', 'publish_stream'],
'METHOD': 'js_sdk',
}
}

Did you override the default allauth templates? If so, please make sure that you add the following to your login template:
{% load socialaccount %}
{% providers_media_js %}
In the default templates, this happens here:
https://github.com/pennersr/django-allauth/blob/27e2a8de0fe3c0c2e65ab8337617eb17a359940c/allauth/templates/account/login.html#L28
The tag adds the required Javascript (if any) for the enabled providers.

Related

How can get country of my shopify store visitor through geolocation?

I want to get shopify store visitor location through geolocation. I tried through this http://www.geoplugin.net/javascript.gp script but when I add this script into the shopify then site goes down. So I need proper solution for the shopify.
After installing the shopify geolocation app and activating it for international market, use the endpoint "browsing_context_suggestions.json" to get the country name as:
fetch('browsing_context_suggestions.json')
.then(res=>res.json())
.then(r=>console.log(r.detected_values.country.name))
You can make use of any IP to location service provider. consider below example.
$.get("https://ipinfo.io/json", function (response) {
console.log(response); // perform your action here
},"jsonp");
Add this script using Script Tag if you are creating an app. otherwise you can add this script on Shopify theme manually.
Another way in the App proxy request shopify gives IP address/ As well as country data in request header.
please follow below screenshot.
in php specif code you can use below code
$headers = apache_request_headers();
echo $headers['Cf-Ipcountry'];
exit;
Shopify Does provide the localization feature. Which detects the local area and map and country. Use the following liquid code to get the list of countries and visitors local country name and code:
<select>
{%- for country in localization.available_countries -%}
<option value="{{ country.iso_code }}" {%- if country.iso_code == localization.country.iso_code %} selected{% endif %}>
{{ country.name }} ({{ country.currency.iso_code }} {{ country.currency.symbol }})
</option>
{%- endfor -%}
</select>

Plaid link not opening w/ rails ENV

After following the Plaid integration tutorial on the Stripe website, I am unable to get the plaid link to work.
I have tried to replace the "env" and "key" variables with environment keys as follows:
<button id='linkButton'>Open Plaid Link</button>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js">
</script>
<script>
var linkHandler = Plaid.create({
env: ENV['PLAID_ENV'],
clientName: 'Divco',
key: ENV['PLAID_PUBLIC_KEY'],
product: ['auth'],
selectAccount: true,
onSuccess: function(public_token, metadata) {
// Send the public_token and account ID to your app server.
console.log('public_token: ' + public_token);
console.log('account ID: ' + metadata.account_id);
},
onExit: function(err, metadata) {
// The user exited the Link flow.
if (err != null) {
// The user encountered a Plaid API error prior to exiting.
}
},
});
// Trigger the Link UI
document.getElementById('linkButton').onclick = function() {
linkHandler.open();
};
When I step back away from having "fancy" environment variables, inserting my keys directly, I don't have an issue. I feel like I have mistyped something... but for my life, I can't find it.
In fact, ENV is a Ruby call. You need to use <%= ENV[*] %> in your javascript and add the .erb extension to your javascript file.
You can use gem like Figaro to easily deal with ENV variables.

Error implementing Django Allauth facebook login on Pythonanywhere : "SocialApp matching query does not exist"

I am trying to implement facebook login using django allauth on pythonanywhere.com.The code I am using works fine on localhost. But the same set of code does not work on pythonanywhere. When I click on the "Facebook Oauth" hyperlink on the login page it takes me to facebook site on localhost.However when I do the same thing on pythonanywhere it gives me following error:
"DoesNotExist at /accounts/facebook/login/
SocialApp matching query does not exist."
Request your support in identifying the root cause.
1.login template :
{% load socialaccount %}
{% block content %}
Facebook OAuth2
settings.py file :
SITE_ID = 3
SOCIALACCOUNT_PROVIDERS = \
{
'facebook': {
'SCOPE': ['email', 'publish_stream'],
#'METHOD': 'js_sdk' ,
'METHOD': 'oauth2',
'LOCALE_FUNC': 'path.to.callable',
#'LOCALE_FUNC': lambda request: return 'en-US',
}
}

Cannot login to yammer using yam.connect.logonButton in IE11

Trying to login using yam.connect.loginButton, works fine on firefox and chrome but not on IE (I am using IE11). The response has an auth but no user object. Or sometimes the popup window doesn't close and the callback is never called. Code I used is below:
<html>
<head>
<script id="yammer-js-include" data-app-id="APP-CLIENT-ID-GOES-HERE" src="https://assets.yammer.com/assets/platform_js_sdk.js"></script>
</head>
<body>
<span id="yammer-login"></span>
<script>
yam.connect.loginButton('#yammer-login',
function (response) {
console.dir(response);
document.getElementById('yammer-login').innerHTML = 'user ' + (typeof response.user !== 'undefined' ? 'exists in response' : 'is missing!');
}
);
</script>
</body>
</html>
You mention that was the code you used, but did you replace the data-app-id with the one provided from your app on https://yammer.com/client_applications ?
Assuming yes, a lot of people run in to problems with IE and not having Yammer urls added to Trusted Sites in IE. If you can add more logs from your console output that it would help.
You can read more about what to include in your Trusted Sites here:
http://developer.yammer.com/connect/#IETrustedSites
When I add the host of where my app was running also in the Trusted Sites, it worked.
http://kendomen.wordpress.com/2014/11/06/yammer-authentication-with-javascript-and-yammer-sdk/

Can Meteor's Backbone Router handle POST requests?

I have a Meteor app which uses a router as per the sample Todos app, eg.:
var TodosRouter = Backbone.Router.extend({
routes: {
":list_id": "main"
},
main: function (list_id) {
...
},
...
});
Router = new TodosRouter;
I have an external service that lets me know when it is finished via a POST request to a URL that I specify. On receiving the POST request, it needs to perform some functions. Can I set this up consistent with the above framework? If not, am I better off writing a separate non-Meteor (eg. nodejs) app to handle the POSTs, or is there a way to make it work within Meteor?
I know this, this and this StackOverflow question are similar, but none of the answers explains how to do it with the Backbone.Router.
Thanks!
Here's how I migrated from the Backbone.Router to Iron-Router. I couldn't see a way to use them both at once.
First, I put code like in #Christian Fritz's answer, in the server folder:
Router.map(function () {
this.route('foo', {
path: '/foo',
where: 'server',
action: function() {
if (this.request.method == 'POST') {
console.log('post request received');
} else {
this.response.writeHead(404);
}
}
})
});
That handles the POST request, as tested by including a console.log in the action (which will write to the terminal window where meteor is running), and typing:
curl --data "p=bar" localhost:3000/foo
Then I replaced the Backbone.Router call with code in the client folder, as described in the Iron-Router docs, eg.
Router.configure({
layoutTemplate: 'layout'
});
Router.map(function () {
this.route('home', {
path: '/',
template: 'homepage',
});
});
Then I had to rewrite my templates so that pages were generated from different templates, instead of from different Session variable settings. This actually simplified my code, eg. instead of:
<body>
{{#if onPage 'home'}}
{{> homepage }}
{{/if}}
{{#if onPage 'help'}}
{{> helppage }}
{{/if}}
...
</body>
and
UI.registerHelper("onPage", function(name) {
return Session.equals('page', name);
});
it's just:
<template name="layout">
{{>yield}}
</template>
Any javascript that needs to direct the user to a specific page uses Router.go() with the route name:
Router.go('home');
Beyond that, I found a few places where I used to be able to assume my collections .findOne() had found one, but seem to have broken with Iron-Router. Wrapping these in ifs fixed them.
In Meteor 0.8, to check what page you are on you can use (see here):
Router.current().lookupProperty('template')

Resources