fixing callback urls

This commit is contained in:
Anupam K 2020-05-06 01:13:51 +05:30
parent 5e3d8050aa
commit d078883cd4
4 changed files with 18 additions and 11 deletions

View File

@ -62,6 +62,8 @@ frappe.ui.form.on('LinkedIn Settings', {
callback : function(r) { callback : function(r) {
window.location.href = r.message; window.location.href = r.message;
} }
}).fail(function() {
frappe.dom.unfreeze();
}); });
} }
}, },

View File

@ -15,7 +15,7 @@ class LinkedInSettings(Document):
params = urlencode({ params = urlencode({
"response_type":"code", "response_type":"code",
"client_id": self.consumer_key, "client_id": self.consumer_key,
"redirect_uri": get_site_url(frappe.local.site) + "/?cmd=erpnext.crm.doctype.linkedin_settings.linkedin_settings.callback", "redirect_uri": get_site_url(frappe.local.site) + "/api/method/erpnext.crm.doctype.linkedin_settings.linkedin_settings.callback?",
"scope": "r_emailaddress w_organization_social r_basicprofile r_liteprofile r_organization_social rw_organization_admin w_member_social" "scope": "r_emailaddress w_organization_social r_basicprofile r_liteprofile r_organization_social rw_organization_admin w_member_social"
}) })
@ -30,7 +30,7 @@ class LinkedInSettings(Document):
"code": code, "code": code,
"client_id": self.consumer_key, "client_id": self.consumer_key,
"client_secret": self.get_password(fieldname="consumer_secret"), "client_secret": self.get_password(fieldname="consumer_secret"),
"redirect_uri": get_site_url(frappe.local.site) + "/?cmd=erpnext.crm.doctype.linkedin_settings.linkedin_settings.callback", "redirect_uri": get_site_url(frappe.local.site) + "/api/method/erpnext.crm.doctype.linkedin_settings.linkedin_settings.callback?",
} }
headers = { headers = {
"Content-Type": "application/x-www-form-urlencoded" "Content-Type": "application/x-www-form-urlencoded"
@ -154,7 +154,7 @@ class LinkedInSettings(Document):
return response return response
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def callback(code=None, error=None, error_description=None): def callback(code=None, error=None, error_description=None):
if not error: if not error:
linkedin_settings = frappe.get_doc("LinkedIn Settings") linkedin_settings = frappe.get_doc("LinkedIn Settings")

View File

@ -47,6 +47,8 @@ frappe.ui.form.on('Twitter Settings', {
callback : function(r) { callback : function(r) {
window.location.href = r.message; window.location.href = r.message;
} }
}).fail(function() {
frappe.dom.unfreeze();
}); });
} }
}, },

View File

@ -12,13 +12,12 @@ from tweepy.error import TweepError
class TwitterSettings(Document): class TwitterSettings(Document):
def get_authorize_url(self): def get_authorize_url(self):
callback_url = "{0}/?cmd=erpnext.crm.doctype.twitter_settings.twitter_settings.callback".format(frappe.utils.get_url()) callback_url = "{0}/api/method/erpnext.crm.doctype.twitter_settings.twitter_settings.callback?".format(frappe.utils.get_url())
auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"), callback_url) auth = tweepy.OAuthHandler(self.consumer_key, self.get_password(fieldname="consumer_secret"), callback_url)
try: try:
redirect_url = auth.get_authorization_url() redirect_url = auth.get_authorization_url()
return redirect_url return redirect_url
except: except tweepy.TweepError as e:
frappe.msgprint(_("Error! Failed to get request token.")) frappe.msgprint(_("Error! Failed to get request token."))
frappe.throw(_('Invalid {0} or {1}').format(frappe.bold("Consumer Key"), frappe.bold("Consumer Secret Key"))) frappe.throw(_('Invalid {0} or {1}').format(frappe.bold("Consumer Key"), frappe.bold("Consumer Secret Key")))
@ -91,8 +90,12 @@ class TwitterSettings(Document):
frappe.db.commit() frappe.db.commit()
frappe.throw(content["message"],title="Twitter Error {0} {1}".format(e.response.status_code, e.response.reason)) frappe.throw(content["message"],title="Twitter Error {0} {1}".format(e.response.status_code, e.response.reason))
@frappe.whitelist() @frappe.whitelist(allow_guest=True)
def callback(oauth_token, oauth_verifier): def callback(oauth_token = None, oauth_verifier = None):
if oauth_token and oauth_verifier:
twitter_settings = frappe.get_single("Twitter Settings") twitter_settings = frappe.get_single("Twitter Settings")
twitter_settings.get_access_token(oauth_token,oauth_verifier) twitter_settings.get_access_token(oauth_token,oauth_verifier)
frappe.db.commit() frappe.db.commit()
else:
frappe.local.response["type"] = "redirect"
frappe.local.response["location"] = get_url_to_form("Twitter Settings","Twitter Settings")